I first discretise a continuous variable using the code below:
ChickWeight2 <-
mutate(ChickWeight,
weight5 = case_when(weight <= 50 ~ 1,
weight > 50 & weight <= 100 ~ 2,
weight > 100 & weight <= 150 ~ 3,
weight > 150 & weight <= 200 ~ 4,
TRUE ~ 5))
and then turn this discrete variable into an ordinal one using base-R functions:
ChickWeight2 <- mutate(ChickWeight2, weight5_2 =
factor(weight5, levels = c(1, 2, 3, 4, 5),
labels = c("very little", "litle",
"medium","big","very big"),
ordered = TRUE))
How can I create this ordinal variable using the functions from the forcats package instead of base R?
question from:
https://stackoverflow.com/questions/65930471/using-the-forcats-package-instead-of-base-r 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…