Skip to content

Remove objects names like character String

5 messages · Katharina May, Uwe Ligges, Henrique Dallazuanna +1 more

#
Hi,

how can I use rm() on objects named like:
paste("site",i,"_data",sep="") while looping
through i?
I tried rm(paste("site",i,"_data",sep="")) but I get the error that
rm() must contain names or
text strings which is confusing me as I thought paste() would create
something like that...?

Thanks,


         Katharina
#
Katharina May wrote:
Well, I would try to avoid the creation of so many objects, but once you 
have them you can do even without a loop:

e.g. for the first 5:

i <- 1:5
do.call("rm", list(paste("site", i, "_data", sep="")))

Uwe Ligges
#
thanks to all your solutions, works out perfectly!


2009/5/19 Henrique Dallazuanna <wwwhsd at gmail.com>:

  
    
#
I don't get the error you mention:
In my example, another way is: rm(list=paste("site",1:3,"_data",sep=""))

Or you can use rm(list=ls(pattern=you pattern)), in my example, it is:
rm(list=ls(pattern="site[1-3]_data"))

Ronggui

2009/5/19 Katharina May <may.katharina at googlemail.com>: