Hello R users, I am trying to run the command rbind gathering the name of tables to bind from a list argument. Unfortunately I am not able to obtain it. I would appreciate any suggestions. Below is a reproducible example with the problem. Thanks Matteo ############################################################## ZA<-data.frame(x = 1:2, y = 1:10,z=letters[1:5]) ZB<-data.frame(x = 1, y = 5:24,z=letters[2]) a<-as.list(ls(pattern= "^Z?"));a ############################################################# I_would_like_ZC<-rbind(ZA,ZB) # this is what I would like to have ############################################################# b<-(paste(a, collapse = ',')) call("rbind",(b)) # I am not able to remove "" b<-noquote(paste(a, collapse = ',')) call("rbind",(b)) # I am not able to remove "" [[alternative HTML version deleted]]
1. It should be: a<-as.list(ls(pattern= "^Z.")) to get "Z" at the beginning and 1 further character. 2. Use do.call() instead of call(). The latter does not evaluate the call; the former does. 3. But most important, the "args" argument of do.call() must be a list of names, not character strings. This can be obtained using as.name(). This can all be effected by: a<-as.list(ls(pattern= "^Z.")) do.call(rbind,lapply(a,as.name)) -- and please post in plain text, not HTML, as HTML often gets mangled when reproduced on this plain text list. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Wed, Jun 17, 2015 at 2:58 AM, Matteo <mmurenu at tiscali.it> wrote:> Hello R users, > > I am trying to run the command rbind gathering the name of tables to bind > from a list argument. > > Unfortunately I am not able to obtain it. > > I would appreciate any suggestions. Below is a reproducible example with > the problem. > > Thanks > > Matteo > > > > ############################################################## > > ZA<-data.frame(x = 1:2, y = 1:10,z=letters[1:5]) > > ZB<-data.frame(x = 1, y = 5:24,z=letters[2]) > > a<-as.list(ls(pattern= "^Z?"));a > > ############################################################# > > I_would_like_ZC<-rbind(ZA,ZB) # this is what I would like to have > > ############################################################# > > b<-(paste(a, collapse = ',')) > > call("rbind",(b)) # I am not able to remove "" > > b<-noquote(paste(a, collapse = ',')) > > call("rbind",(b)) # I am not able to remove "" > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
I *think* you want: ZC <- do.call(rbind,lapply(a,get)) But why do you make "a" a *list* of names rather than a vector of names? Generally one uses lists to hold "complicated" structures. A sequence of character scalars is best stored in an atomic vector. cheers, Rolf Turner P. S. Thank you for providing a reproducible example! :-) R. T. On 17/06/15 21:58, Matteo wrote:> Hello R users, > > I am trying to run the command rbind gathering the name of tables to bind > from a list argument. > > Unfortunately I am not able to obtain it. > > I would appreciate any suggestions. Below is a reproducible example with > the problem. > > Thanks > > Matteo > > > > ############################################################## > > ZA<-data.frame(x = 1:2, y = 1:10,z=letters[1:5]) > > ZB<-data.frame(x = 1, y = 5:24,z=letters[2]) > > a<-as.list(ls(pattern= "^Z?"));a > > ############################################################# > > I_would_like_ZC<-rbind(ZA,ZB) # this is what I would like to have > > ############################################################# > > b<-(paste(a, collapse = ',')) > > call("rbind",(b)) # I am not able to remove "" > > b<-noquote(paste(a, collapse = ',')) > > call("rbind",(b)) # I am not able to remove ""-- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276