我正在尝试根据未检测到的字符串和列中的当前值有条件地更改列中的值。
starwars %>%
mutate(
species = case_when(
!str_detect(name, "Luke Skywalker") |
!str_detect(name, "LUKE SKYWALKER") |
!str_detect(name, "Darth Vader") |
!str_detect(name, "DARTH VADER") &
species == "Human"
~ "Other",
.default = species
)
)
结果是物种的所有值都变成“其他”。我本以为只有人类角色(不是卢克·天行者或达斯·维达)是“其他物种。