Wednesday, 15 May 2013

r - elegant way to use rbind() on multiple dataframes with similar names? -


Currently, I have multiple codeframes ( foo1 , with the same name and in the running order) Foo 2 , foo3 , foo4 , foo5 ... etc). I am trying to create a large data frame containing the rbind () with all rows of dataframes above. will be equal to rbind (foo1, foo2, foo3, foo4, foo5 ...)

I have tried Do.call (rbind, paste0 ("Foo", i)) where i = c (1,2,3 ...) no benefit.

is one, which is: do.matrix & lt; - do.call (get rbind, lapply (paste0 ("variable", 1:10),)

However, the answer is mysteriously saying, "to handle related items This is a wrong way. It is better to use list or dataframe, but you probably will know why that is the reason. "

Why is it wrong to do this, and what will be the "right" way?

Thank you.

Always relate relationships between related data, or related data and methods, or related examples of related methods Try to catch it generally helps to reduce overall manipulation such as your rbind requirement.

For your case, you get your related data. The frame should have been defined as a list from the beginning:

  foo & lt; - list (data.frame (...), data.frame (...), ...);  

And then your requirement may be satisfied as follows:

  do.call (rbind, foo);  

If it is too late for it, then the caller's solution to the get () , as you mentioned in the article could work .


No comments:

Post a Comment