Re: [R] rbind with partially overlapping column names

From: Ian Gow <>
Date: Sun, 15 May 2011 19:50:31 -0500


This is a bit of a kluge, but works for your test case:

> df2[,setdiff(names(df1),names(df2))] <- NA
> df1[,setdiff(names(df2),names(df1))] <- NA
> df3 <- rbind(df1,df2)
> df3

a b c
1 A B <NA>
2 A B <NA>
3 <NA> b c
4 <NA> b c


On 5/15/11 7:41 PM, "Jonathan Flowers" <> wrote:

>I would like to merge two data frames with partially overlapping column
>names with an rbind-like operation.
>For the follow data frames,
>df1 <- data.frame(a=c("A","A"),b=c("B","B"))
>df2 <- data.frame(b=c("b","b"),c=c("c","c"))
>I would like the output frame to be (with NAs where the frames don't
>a b c
>NA b c
>NA b c
>I am familiar with ?merge and ?rbind, but neither seem to offer a means to
>accomplish this.
>Thanks in advance.
> [[alternative HTML version deleted]]
> mailing list
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code. mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 16 May 2011 - 00:54:28 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Mon 16 May 2011 - 02:40:07 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive