【发布时间】:2020-07-04 04:52:25
【问题描述】:
如果我们有一个 data.frame ,请说类似
///// !col1!col2!col3
---------------
id123 1 0 0
---------------
!id435 0 1 0
---------------
!id777 0 0 1
我想创建一个新列 newcol,其中变量名称的值具有 '1'
需要数据
///// !col1!col2!col3!newcol
---------------------
id123 1 0 0 !col1
---------------------
!id435 0 1 0 !col2
---------------------
!id777 0 0 1 !col3
1) 有没有办法在 base 或 plyr 中做? 2)(可选)如果 id123 在 col1 和 col2 中都有值 1 ,如何调整它?如何“添加”这些值,在 newcol 中用逗号分隔
temp$col1 <- c(1,0,0)
temp$col2 <- c(0,1,0)
temp$col3 <- c(0,0,1)
temp<-data.frame(temp$col1, temp$col2, temp$col3)
感谢您的支持 :)
【问题讨论】:
标签: r dataframe dplyr tidyverse plyr