I'm trying to use case_when() in tidyverse but specifically to output a particular category when any value in the grouped row of a column is present or not...
Dummy data (d):
ID Tired
1A No
1A No
1A Yes
1B No
1B No
IC Yes
ID No
ID No
I want the output to classify whether each ID is tired or not. However, if the ID has said they are tired at least once, they count as tired and they are categorised as "Y". If they say no to being tired everytime, it is "N".
Desired output (output):
ID Tired Category
1A No Y
1A No
1A Yes
1B No N
1B No
IC Yes Y
ID No N
ID No
I have some code, but it's falling down as I don't know how to code for the situation the category classification occurs once across a group, within a column:
output <- d %>% group_by(ID) %>% mutate(Category = case_when(
Tired == "Yes" ~ Y,
(TRUE) ~ N))
Any help would be gratefully received!