[R] rbind() problem

Tobias Verbeke tobias.verbeke at telenet.be
Sat Jun 14 07:45:24 CEST 2008


Hi array (?),

> Hi, I would like to rbind 2 data frames. They both some common column names, but also some unique column names each, is there any simple function that rbind these 2 data frames with filling NAs for those columns of unique names?

You can use the reshape package by Hadley Wickham for this:


df1 <- data.frame(V1 = rnorm(10),
                   V2 = rnorm(10),
                   V4 = rnorm(10))
df2 <- data.frame(V1 = rnorm(10),
                   V3 = rnorm(10),
                   V4 = rnorm(10))
library(reshape)
rbind.fill(df1, df2)

HTH,
Tobias



More information about the R-help mailing list