ifelse with multiple conditions and categories

Hey everybody!

I need to generate a new categoric variable for a measured laboratory parameter. This variable should show whether the measured parameter is above or under the limit. Yet, the limits are dependent on age and gender:

Translation: Männer = Male, Frauen = Women, Alter = Age
image

I tried it with something like this:

data <- data %>%
mutate(cat_variable = ifelse(gender == "male" | age < 44,
cut(parameter,
c(0, 90.8, Inf),
c("okay", "elevated"),
ifelse(gender == "male" | age <.... and this is were i get lost as I don't know how to merge all these conditions

does anybody have a solution for this problem?

Thanks in advance!

You may want to explore case_when() for this.

It would be helpful if you'd post a sample of your "before" data frame and what you'd like it to look like "after" the new variable is added.

This topic was automatically closed 21 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.