Search code examples
rdataframecbind

Dumb rbind for data.frames of different length


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

Solution

  • You want cbind not rbind.

    Try :

    a = c(1:3)
    b = c(1:2)
    
    length(b) = length(a)
    
    cbind(a, b)