Using case_when instead of ifelse to create a new variable

Was wondering if anyone would be able to help me in turning an ifelse() statement into case_when(), accompanied with mutate to create a new variable.

I haven't attached a reprex as I'm unsure if it would be needed, but will add one if so.

Thanks for any help.

ifelse(adherence.test$date %in% exac.filter$exac.start & 
         adherence.test$patientid %in% exac.filter$patientid, 
         as.character(adherence.test$date), NA)

#Attempt
adherence.test <- Adherence.merge %>% 
                  mutate(exac.date = ifelse(adherence.test$date %in% 
                  exac.filter$exac.start &  adherence.test$patientid %in% 
                  exac.filter$patientid, as.character(adherence.test$date), 
                  TRUE ~ NA))

Error: Column `exac.date` must be length 1 (the group size), not 320

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Having a sample of your data will be very helpful in diagnosing the issue you are having. Please have a look at this guide, to see how to create one:

1 Like

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