mutate() and case_when() function

Hello All - finally I was able to successfully run the code sent by FJCC (Thanks a lot) and got my desired dataset.

However, I have a question:

I was running this code:

visadsl <- vis |> filter(ACTARMCD %in% c("VEDOIV_VEDOSC", "VEDOIV_PSC")) |>
mutate(trtn = case_when(
ACTARMCD == "VEDOIV_VEDOSC" ~ 1,
ACTARMCD == "VEDOIV_PSC" ~ 2,
TRUE ~ NA #This line shouldn't be necessary because actarmcd should have only two values
)) |>
select(USUBJID, trtn)

and was getting this error:

<error/dplyr:::mutate_error>
Error in mutate():
! Problem while computing trtn = case_when(...).
Caused by error in case_when():

I read that both mutate() and case_when() functions are available in dplyr package whick is a part of tidyverse package. But the code only ran successfully when I installed tidyverse package.

Any idea what could be the reason?

Sharif

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