hi netters, suppose i have a series of objects X1, X2, B1,C1........... they all have the same dimensions. i want to combine into one by using cbind: y<-cbind(X1,X2,B1,C1.....) but i don't want to type the names of these objects one by one. instead, i've put their names into a vector: x<-c("X1","X2","B1","C1",....) i used y<-cbind(x). but what i got is a matrix of the names, not a combination of matrices. anybody know how to handle this? thanks a lot!
try: y <- sapply(x, function(x) eval(parse(text=x))) zhihua li a 仺仸crit :> hi netters, > > suppose i have a series of objects X1, X2, B1,C1........... they all > have the same dimensions. i want to combine into one by using cbind: > y<-cbind(X1,X2,B1,C1.....) > > but i don't want to type the names of these objects one by one. > instead, i've put their names into a vector: > x<-c("X1","X2","B1","C1",....) > > i used y<-cbind(x). but what i got is a matrix of the names, not a > combination of matrices. > > anybody know how to handle this? > > thanks a lot! > >------------------------------------------------------------------------ > >______________________________________________ >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 >
Kjetil Brinchmann Halvorsen
2005-Dec-12 13:25 UTC
[R] store and retrieve object names in a vector
zhihua li wrote:> hi netters, > > suppose i have a series of objects X1, X2, B1,C1........... they all > have the same dimensions. i want to combine into one by using cbind: > y<-cbind(X1,X2,B1,C1.....) > > but i don't want to type the names of these objects one by one. instead, > i've put their names into a vector: x<-c("X1","X2","B1","C1",....)Something like: do.call(rbind, lapply(x,get)) # not tested should work! Kjetil> > i used y<-cbind(x). but what i got is a matrix of the names, not a > combination of matrices. > > anybody know how to handle this? > > thanks a lot! > > > ------------------------------------------------------------------------ > > ______________________________________________ > 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
Seemingly Similar Threads
- how to change a dataframe with characters to a numeric matrix?
- how to use a function in aggregate which accepts matrix and outputs matrix?
- An R clause to bind dataframes under certain contions
- Error: evaluation nested too deeply when doing heatmap with binary distfunction
- locate the rows in a dataframe with some criteria