I am trying to do something that I think is straightforward but I am having an issue with.
I have several medication-related column variables (med_1
, med_2
, med_3
for example). These are character variables- so they have text for the name of medications
I want to combine them all into variable anymed
using or logic, so that I can then use anymed
to look at any medications reported across all medication related fields.
I am trying the following, for dataset FinalData.
FinalData <- FinalData %>% mutate(anymed = med_1 | med_2 | med_3)
I am receiving this error:
*Error: Problem with `mutate()` column `anymed`.
ℹ `anymed = |...`.
x operations are possible only for numeric, logical or complex types*
Could someone help explain what code I should use instead since these are characters? Do I need to convert to factors?