0

I want to use smartbind() to merge 20+ dataframes. These data frames have different number of observations (rows). Most of their columns have the same names though some differ. I have named them like this:

data.Argentina  
data.Brazil  
data.Venezuela

Then, I wrote

library(gtools)
combined.data  <- smartbind(mget(ls(pattern = "^data.")))

The error information is :

Error in data.frame(data.Argentina = list(pais = c(1L, 1L, 1L, 1L, 1L, : arguments imply differing number of rows: 1512, 3429, 1533, 3067, 1500, 1571, 1510, 1537, 1520, 1489, 1507, 1557, 1561, 1503, 1535, 1546, 1508, 4000, 4203

Then, I have to do it by manually listing all data frames:

combined.data <- smartbind (data.Argentina, data.Brazil, data.Venezuela)

This time it works!

So could I use other functions or other commands to make the process simpler?

Thank you!

thelatemail
  • 91,185
  • 12
  • 128
  • 188
Li_S
  • 21
  • 1
  • 2
  • Where are you getting your `smartbind` function from? Be sure to include an non-default R packages you may be using. Also, it would help if you provided a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – MrFlick Nov 03 '15 at 23:28
  • It is from gtools. I hope to provide an example but my data is too large to upload. – Li_S Nov 03 '15 at 23:29
  • Surely you can provide an example with fake data then that reproduces your problem, no? – MrFlick Nov 03 '15 at 23:30

1 Answers1

3

Passing a bunch of arguments in a list is not the same as passing them separately. The do.call command can expand a list into different parameters. Try

combined.data <- do.call("smartbind", mget(ls(pattern = "^data.")))
MrFlick
  • 195,160
  • 17
  • 277
  • 295