[R] how to use do.call("rbind", get(list(mlist)))
Thomas Lumley
tlumley at u.washington.edu
Fri Jan 21 19:31:53 CET 2005
On Fri, 21 Jan 2005, roger bos wrote:
> I have around 200 data frames I want to rbind in a vectorized way.
> The object names are:
>
> m302
> m303
> ...
> m500
>
> So I tried:
>
> mlist <- paste("m",302:500,sep="")
> dat <- do.call("rbind", get(list(mlist)))
>
> and I get "Error in get(x, envir, mode, inherits) : invalid first argument"
Yep. get() takes a single variable name as its argument.
If you tried get(list("m302","m303")) you would get the same error.
> I know "rbind" is valid because
>
> dat <- rbind(m302, m303, m304, m305)
>
> works, I am just too lazy to type it out to m500.
>
> I also tried it without the get() portion, but then dat ends up being
> a column with just the names of the objects, not the objects
> themselves.
Indeed. This translates to rbind("m302","m303"....
You could use mget() instead of get().
-thomas
More information about the R-help
mailing list