1

I would like to stack vertically two data frames that do not match in variables. For the variables that do not appear in one of the data frames, I would like the variables to be filled in with whatever missing values are appropriate NA or "" as the case may be. I would program something myself but I hate to reinvent the wheel if someone already has programmed this tool.

A <- data.frame(a=1:10, b=rnorm(10), c=rnorm(10))
B <- data.frame(a=1:10, c=rnorm(10), d=rnorm(10))
Jaap
  • 81,064
  • 34
  • 182
  • 193
Francis Smart
  • 3,875
  • 6
  • 32
  • 58

1 Answers1

1

You can use rbindlist after keeping the data.frames in a list

library(data.table)#v1.9.5+
rbindlist(list(A,B), fill=TRUE)

Or

library(dplyr)
bind_rows(A,B)

Or

library(plyr)
rbind.fill(A, B)
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
akrun
  • 874,273
  • 37
  • 540
  • 662