Currently, i have multiple dataframes with the same name and in running order (foo1, foo2, foo3, foo4, foo5... etc). I am trying to create a large dataframe containing all the rows of the above dataframes with rbind(). Is there an elegant way to do it which would be the equivalent of rbind(foo1, foo2, foo3, foo4, foo5...)?
I have tried do.call(rbind, paste0("foo",i)) where i=c(1,2,3...) to no avail.
There is a solution mentioned here, which is:
do.matrix <- do.call(rbind, lapply( paste0("variable", 1:10) , get) )
However, the answer mysteriously says "That is the wrong way to handle related items. Better to use a list or dataframe, but you will probably find out why in due course."
Why would that be the wrong way to do this, and what would be the "right" way?
Thanks.
foo1,foo2, etc in the first place. If you had put them all in a single list in the first place, you can just pass that list todo.calland be done with it.assign. This is not recommended, since you may overwrite other objects and you may not be able to retrieve all the objects effectively. Much better to initialise alistand then set each element of it as one of your data.frames. Anyway,do.call(rbind,mget(paste0("foo",1:N)))should work in your example ifNis the number of the data.frames.