2

Assume that I have the following 100 variables that already have assigned values. This means, I am loading them.

Their assigned names are identical, except for the ending, they end in different numbers:

i.e. D1=23, D2=45,...,D100=67

Is there a quick and efficient way to bind them, preferably as rows. Obviously I could:

D_ALL<-rbind(D1,D2,..,D100)

But is there a quicker way to handle this?

For instance, a loop such as:

for(i in seq(from=1, to=100, by=1))
{
D[i]<-D$i
 }

This sort of loop is not going to work in R (it would in STATA with the dollar $ sign).

I am wondering if there is a solution to this. Thanks.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Marcus
  • 21
  • 1
  • 1
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Sep 15 '17 at 07:16
  • 5
    Just do `library(data.table);rbindlist(mget(paste0("D", 1:100)))` or with `base R` `do.call(rbind, mget(paste0("D", 1:100)))` – akrun Sep 15 '17 at 07:17
  • Thank you so much! It was the "do.call" function that I was unaware of. – Marcus Sep 15 '17 at 21:35

0 Answers0