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
  • 77,147
  • 31
  • 174
  • 185
Francis Smart
  • 3,544
  • 5
  • 30
  • 55

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
  • 74,560
  • 11
  • 127
  • 189
akrun
  • 789,025
  • 32
  • 460
  • 575