df1 <- data.frame(a = 1:2, b = 3:4) df2 <- data.frame(a = 5:6, b = 7:8) # A common method loses the origin of each row. do.call("rbind", list(df1, df2)) ## ab ## 1 1 3 ## 2 2 4 ## 3 5 7 ## 4 6 8 # Whereas here, X1 records which data frame each row originated in. library(plyr) adply(list(df1, df2), 1) ## X1 ab ## 1 1 1 3 ## 2 1 2 4 ## 3 2 5 7 ## 4 2 6 8
Are there other ways to do this, perhaps more efficiently?
source share