[R] how to use do.call("rbind", get(list(mlist)))

Wiener, Matthew matthew_wiener at merck.com
Fri Jan 21 19:17:20 CET 2005


Roger --

First, if you have the data frames in a list already, you can just use
those; no need to bother with the names.  If the data frames are all
separate, but you have the names, you can first create a list of the data
frames themselves:

do.call("rbind", lapply(mlist, get))  # assumes they're in the workspace

An example:
> temp1 <- matrix(runif(10), 5, 2)
> temp2 <- matrix(-runif(10), 5, 2)   (for easy identifiability)
> temp3 <- do.call("rbind", lapply(c("temp1", "temp2"), get))
> temp3 <- do.call("rbind", list(temp1, temp2))     (same as above)

Hope this helps,

Matt Wiener

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of roger bos
Sent: Friday, January 21, 2005 12:07 PM
To: r-help at stat.math.ethz.ch
Subject: [R] how to use do.call("rbind", get(list(mlist)))


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"

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.

Thanks in advance for showing me the errors in my attempts.

Roger

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list