Creating a categorical variable based from numerical variable

Thank you! It is now solved.

should be ifelse and the other syntax has difficulties, but let's use when instead

heart <- heart %>%
  mutate(age_bracket = when(
    age < 29 ~ NA,
    age %in% 29:44 ~ "Young",
    age %in% 45:60 ~ "Middle",
    age %in% 61:77 ~ "Old",
    age > 77 ~ NA

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.