让我们说我想搜索一个字符串,如果找到了,我既要在新列中指定一个新条目,又要从原始字符串中删除该条目
示例:
OriginalString
The cat sat on the mat
所需结果
OriginalString New Column
The sat on the mat A mammal
mydf%>% mutate(NewColumn=case_when(grepl("cat",OriginalString ~ "A mammal" BUT ALSO gsub("cat", "",OriginalString)