【发布时间】:2020-09-05 01:27:57
【问题描述】:
我有一个清单如下:
c1 <-("apple", "tree", "husband")
还有这个数据:
df <-data.frame(
ID = c("b","b","b","a","a","c"),
col = c("husband", "apple", "juice", "happy", "husband", "white"),
)
我想要这个输出:
df <-data.frame(
ID = c("b","b","b","a","a","c"),
col = c("husband", "apple", "juice", "happy", "husband", "white"),
c1 = c("1","1","0","0","1","0")
)
通过应用列表 (c1) 作为条件并且不使用
mutate(c1= ifelse(col==happy | col==tree | col==husband,1,0))
谢谢
【问题讨论】:
标签: r data-cleaning