使用3组对列进行变异-dplyr
如何根据现有列使用不同的名称对新列进行变异 资料 输出使用3组对列进行变异-dplyr,r,dplyr,R,Dplyr,如何根据现有列使用不同的名称对新列进行变异 资料 输出 index value type a 2 good b 3 bad c 2 good d 5 exceptional 我假设value是确定类型的现有列。当出现以下情况时,可以使用case\u: library(dplyr) df %>% mutate(type = case_when(value == 2 ~ "good", value == 3 ~
index value type
a 2 good
b 3 bad
c 2 good
d 5 exceptional
我假设
value
是确定类型的现有列。当
出现以下情况时,可以使用case\u:
library(dplyr)
df %>%
mutate(type = case_when(value == 2 ~ "good",
value == 3 ~ "bad",
value == 5 ~ "exceptional")
我假设value
是确定类型的现有列。当
出现以下情况时,可以使用case\u:
library(dplyr)
df %>%
mutate(type = case_when(value == 2 ~ "good",
value == 3 ~ "bad",
value == 5 ~ "exceptional")