smartbind {gtools} | R Documentation |
Efficient rbind of data frames, even if the column names don't match
smartbind(...)
... |
Data frames to combine |
The returned data frame will contain:
columns |
all columns present in any provided data frame |
rows |
a set of rows from each provided data frame, with values
in columns not present in the given data frame filled with missing
(NA ) values. |
Gregory R. Warnes greg@random-technologies-llc.com
df1 <- data.frame(A=1:10, B=LETTERS[1:10], C=rnorm(10) ) df2 <- data.frame(A=11:20, D=rnorm(10), E=letters[1:10] ) # rbind would fail ## Not run: rbind(df1, df2) # Error in match.names(clabs, names(xi)) : names do not match previous # names: # D, E ## End(Not run) # but smartbind combines them, appropriately creating NA entries smartbind(df1, df2)