Using comments by Make212 and Renu, here's one option for fixing it:
library(dplyr)
mutate(x,
perfLev = case_when(
SS < 1438 ~ "Below Basic",
SS >= 1439 & SS <= 1499 ~ "Basic",
SS >= 1500 & SS <= 1545 ~ "Proficient",
SS >= 1546 ~ "Advanced",
TRUE ~ "huh?"
) )
I added a "default" (TRUE
), which is generally good (explicit code). Note that if you do not include the TRUE
, then it would get an NA
value, in case that's what you want. I can see it happening here if any of the following are true:
is.na(SS)
SS >= 1438 & SS < 1439
SS > 1499 & SS < 1500
SS > 1545 & SS < 1546
You may not need it if NA
is acceptable and you are guaranteed of SS
's integrality.
This code is equivalent to a slight fix to your code:
mutate(x,
perfLev =
ifelse(SS < 1438, "Below Basic",
ifelse(SS >= 1439 & SS <= 1499, "Basic",
ifelse(SS >= 1500 & SS <= 1545, "Proficient",
ifelse(SS >= 1546, "Advanced", "huh?"))))
)
Indentation for style/clarity only.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…