这是我的数据
decay<- c("None", "None", "11, 55, 64", "None", "54, 66, 74", "47, 74, 55")
我想将所有数字列表转换为"Yes"
。我该怎么办?
答案 0 :(得分:3)
可能您需要:
decay[grepl("\\d", decay)] <- "Yes"
decay
#[1] "None" "None" "Yes" "None" "Yes" "Yes"
答案 1 :(得分:1)
尝试使用gsub
:
> gsub(".*\\d.*","Yes",decay)
[1] "None" "None" "Yes" "None" "Yes" "Yes"
答案 2 :(得分:1)
也许可以尝试相反的选择,任何不是“无”的内容都是“是”:
decay[ decay != "None" ] <- "Yes"
decay
# [1] "None" "None" "Yes" "None" "Yes" "Yes"