[R] how to use do.call("rbind", get(list(mlist)))
McGehee, Robert
Robert.McGehee at geodecapital.com
Fri Jan 21 19:13:40 CET 2005
get() doesn't take a list. You need to wrap it in an lapply so that it
grabs the dataframes individually and then wraps it into a list for
do.call().
The easy way, however, that doesn't involve do.call or get is to simply
construct the proper text rbind query and then run it with eval.
eval(parse(text = paste("rbind(", paste("m", 302:500, sep = "", collapse
= ", "), ")")))
To use the do.call() / get() construct, I think this is what you were
thinking of:
mlist <- paste("m",302:500,sep="")
do.call("rbind", lapply(mlist, get))
Best,
Robert
-----Original Message-----
From: roger bos [mailto:roger.bos at gmail.com]
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