[R] Remove objects names like character String

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue May 19 15:19:07 CEST 2009

Katharina May wrote:
> 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...?

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,
>          Katharina

More information about the R-help mailing list