2

I don't need any smart rbind, like rbindlist, rbind.fill, bind_row and other.

I need a dumb rbind to simply bind two dataframes:

> a <- data.frame(a = 1:3)
> b <- data.frame(b = 1:2)

> some.magic.bind(a, b) # what function to use here?

   a  b
1  1 1
2  2 2
3  3 NA
vagabond
  • 3,526
  • 5
  • 43
  • 76
m0nhawk
  • 22,980
  • 9
  • 45
  • 73

2 Answers2

9

You want cbind not rbind.

Try :

a = c(1:3)
b = c(1:2)

length(b) = length(a)

cbind(a, b)
vagabond
  • 3,526
  • 5
  • 43
  • 76
5

merge works directly on two data.frames of different length and will keep it as a data.frame:

merge(a,b,by="row.names",all.x=TRUE)[,-1]
  a  b
1 1  1
2 2  2
3 3 NA
J.R.
  • 3,838
  • 1
  • 21
  • 25