Merging two columns into one in R

后端 未结 7 920
情深已故
情深已故 2020-11-29 02:06

I have the following data frame, and am trying to merge the two columns into one, while replacing NA\'s with the numeric values.

ID    A     B
1         


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 02:41

    You can use unite from tidyr:

    library(tidyr)
    
    df[is.na(df)] = ''
    unite(df, new, A:B, sep='')
    #  ID new
    #1  1   3
    #2  2   2
    #3  3   4
    #4  4   1
    

提交回复
热议问题