猿问

当两个数据帧有不同的列集时,按行组合两个数据帧(Rbind)

当两个数据帧有不同的列集时,按行组合两个数据帧(Rbind)

行绑定不具有相同列集的两个数据帧可以吗?我希望保留绑定后不匹配的列。



潇潇雨雨
浏览 701回答 3
3回答

慕姐4208626

rbind.fill从包裹里plyr可能就是你要找的。

胡子哥哥

最近的一个解决方案是使用dplyr氏bind_rows函数,我假设它比smartbind.

慕标5832272

你可以用smartbind从gtools包裹。例子:library(gtools)df1 <- data.frame(a = c(1:5), b = c(6:10))df2 <- data.frame(a = c(11:15), b = c(16:20), c = LETTERS[1:5])smartbind(df1, df2)# result&nbsp; &nbsp; &nbsp;a&nbsp; b&nbsp; &nbsp; c1.1&nbsp; 1&nbsp; 6 <NA>1.2&nbsp; 2&nbsp; 7 <NA>1.3&nbsp; 3&nbsp; 8 <NA>1.4&nbsp; 4&nbsp; 9 <NA>1.5&nbsp; 5 10 <NA>2.1 11 16&nbsp; &nbsp; A2.2 12 17&nbsp; &nbsp; B2.3 13 18&nbsp; &nbsp; C2.4 14 19&nbsp; &nbsp; D2.5 15 20&nbsp; &nbsp; E
随时随地看视频慕课网APP
我要回答