Skip to content
Prev 302338 / 398503 Next

add vectors to multiple objects

On Aug 3, 2012, at 2:11 PM, R. Michael Weylandt wrote:

            
Heh. Users of this should realize that Michael probably did this in  
clean session. If you run it with any other items in the workspace  
that have  "3" in their names they get wrapped up too. I had a 300  
line dataframe as well as a function whose values both got gathered up.

In the case where one needed to isolate a disjoint group of items, one  
might want to create an environment in which to segregate those items.  
the ls function can be directed to look in only one environment.

I wondered if this were the route intended:

for( i in seq_along(ls(patt=".lst") ) ) {
            assign( ls(patt=".lst")[i],  # the name of the i-th ".lst"- 
item
                    append(
                       sapply(ls(patt=".lst$"), get)[i],  # the  
original value
                       sapply(ls(patt="^L\\d"), get)[i] ) )} # the  
appended i-th "L"-value

I think it is far from optimal to have a loose collection of objects  
in the workspace. Much better to have them all in one list or an  
environment.