Check the bind_rows function. By default, you will do some nice things for you, such as filling columns that exist in one data.frame , but not others with NA , and not just crashing. Here is an example:
# Use the dplyr package for binding rows and for selecting columns library(dplyr)
To solve the problem in your question, you must first select for the columns in your main data.frame . If a is the leading data.frame and b contains the data you want to add, you can use the select function from dplyr to get the columns you need.
# Select all columns in b with the same names as in master data, a # Use select_() instead of select() to do standard evaluation. b <- select_(b, names(a)) # Combine bind_rows(a, b) Source: local data frame [15 x 2] ab 1 2.2891895 0.1940835 2 0.7620825 -0.2441634 3 1.8289665 1.5280338 4 -0.9851729 -0.7187585 5 1.5829853 1.6609695 6 0.9231296 1.8052112 7 -0.5801230 -0.6928449 8 0.2033514 -0.6673596 9 -0.8576628 0.5163021 10 0.6296633 -1.2445280 11 2.1693068 NA 12 -0.1048966 NA 13 0.2673514 NA 14 1.0937759 NA 15 -0.8147180 NA
source share