Re: [R] rbind() problem

From: Tobias Verbeke <tobias.verbeke_at_telenet.be>
Date: Sat, 14 Jun 2008 07:45:24 +0200

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



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 14 Jun 2008 - 05:51:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 14 Jun 2008 - 06:30:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive