Last active
August 29, 2015 14:24
-
-
Save PhillRob/187ffd624576ed9e0d6d to your computer and use it in GitHub Desktop.
rbind data frames with miss matching columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rbind.keep.columns <- function(x, y) { | |
x.dif <- setdiff(colnames(x), colnames(y)) | |
y.dif <- setdiff(colnames(y), colnames(x)) | |
x[, c(as.character(y.dif))] <- NA | |
y[, c(as.character(x.dif))] <- NA | |
return(rbind(x, y)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
inspired by https://amywhiteheadresearch.wordpress.com