cbind a dataframe with an empty dataframe - cbind.fill?

后端 未结 9 1786
野的像风
野的像风 2020-11-22 11:25

I think I\'m looking for an analog of rbind.fill (in Hadley\'s plyr package) for cbind. I looked, but there is no cbind.fill

9条回答
  •  天涯浪人
    2020-11-22 12:05

    When a and b are data frames, following should work just fine:

    ab <- merge(a, b, by="row.names", all=TRUE)[,-1]
    

    or another possibility:

    rows <- unique(c(rownames(a), rownames(b)))
    ab <- cbind(a[rows ,], b[rows ,])
    

提交回复
热议问题