【发布时间】:2021-09-14 13:05:09
【问题描述】:
我在 df 中有这个专栏:
| Column1 |
|---|
| very sunny day today |
| it was sunny |
| not very sunny today |
想要的输出
| Column1 |
|---|
| sunny |
| sunny |
| not sunny |
df<-df%>%
mutate(column_1=case_when(
str_detect(column_1,"very sunny")~ "sunny",
str_detect(column_1,"sunny")~ "sunny",
str_detect(column_1,"not"&"sunny")~ " not sunny",
)
)
该代码适用于前两行,其中我们对第三行的条件更简单,条件更复杂并给我一个错误。
我想确定该字符串中的一些关键字,它们不在一起(非常阳光)但它们是分开的(今天不是很阳光),并将它们作为提供所需输出的条件。也许我在语法上做错了什么。
【问题讨论】:
标签: r string-substitution