How can I evaluate a string of class character as data frame?
Concretely, I have several data frames let's say: x0,x1,x3:
x0 <- data.frame(a=1,b="a")
x1 <- data.frame(a=2,b="b")
x2 <- data.frame(a=3,b="c")
They have all the same structure and I would like to merge them with rbind
. To avoid to call each single data frame I use regular expression:
x <- grep("x\\d",ls(),perl=TRUE,value=TRUE)
This gives me a vector of class character. Now, I would like to merge them to one dataframe called x.all
:
x.all <- rbind(x)
What I get is a matrix with dimension (1,3). Does anyone can give me a hint? Thanks very much for help.
Using get
and do.call
:
do.call(rbind, lapply(x, get))
# a b
# 1 1 a
# 2 2 b
# 3 3 c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With