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

后端 未结 9 1827
野的像风
野的像风 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 11:58

    We can use a list instead of data.frame and convert it to a data.frame at the end. For instance:

    df = list()
    df2 = data.frame(col1 = 1:3, col2 = c('a','b','c'))
    df = as.data.frame(cbind(df, as.matrix(df2)))
    df
    
    #   col1 col2
    # 1    1    a
    # 2    2    b
    # 3    3    c
    

提交回复
热议问题