dplyr::bind_rows(df1,df2)
# Warning in bind_rows_(x, .id) :
# Unequal factor levels: coercing to character
# Warning in bind_rows_(x, .id) :
# binding character and factor vector, coercing into character vector
# Warning in bind_rows_(x, .id) :
# binding character and factor vector, coercing into character vector
# Name Age School
# 1 Steve 10 <NA>
# 2 Peter 20 <NA>
# 3 Jason NA xyz
# 4 Nelson NA abc
Вы можете облегчить некоторые из этих ситуаций, предварительно назначив нераспознанные столбцы, что также хорошо работает с базовым R:
df2 <- cbind(df2, df1[NA,setdiff(names(df1), names(df2)),drop=FALSE])
df1 <- cbind(df1, df2[NA,setdiff(names(df2), names(df1)),drop=FALSE])
df1
# Name Age School
# NA Steve 10 <NA>
# NA.1 Peter 20 <NA>
df2
# Name School Age
# NA Jason xyz NA
# NA.1 Nelson abc NA
# ensure we use the same column order for both frames
nms <- names(df1)
rbind(df1[,nms], df2[,nms])
# Name Age School
# NA Steve 10 <NA>
# NA.1 Peter 20 <NA>
# NA1 Jason NA xyz
# NA.11 Nelson NA abc