Help with For and mutate

Welcome to the community!

I think you may be overcomplicating a little bit. What you shared is not replicable, as we don't know what is quintilesH. But what I understand from the rest of the code is that you're not using case_when correctly.

You are supposed to use case_when in this format:

case_when(condition_1 ~ expected_result_in_condition_1,
          condition_2 ~ expected_result_in_condition_2,
          ...,
          condition_n ~ expected_result_in_condition_n,
          TRUE ~ expected_result_when_all_other_condition_fail)

Don't use each condition in a different call. And also for this specific use, check the cut and findInterval functions.

If you face any problem, please provide more details in for of a reproducible example (reprex). If you are unfamiliar with what that is, check this FAQ.

And, you're using rlang in your first week of R journey!! I'm using it for almost 5 years, and I know I have never used deep tidyverse stuff. Little bit of common dplyr and purrr is enough for what I do, though I must admit I don't really use R much other than statistics assignments.

1 Like