My df contains demographic information on 50 people. I have a column in my df called "Ethnicity" which contains a lot of ethnicity categories including "White British", "White Other", and "White Irish". I want to create a new column where all observations with one of these 3 values is classified as "White", and all observations which don't start with "White" are classified as "POC".
df %>% mutate(Status = case_when(startsWith(Ethnicity, "White") ~ "White"))
I get the following error
Error in `mutate()`:
! Problem while computing `Status = case_when(startsWith(Ethnicity,
"White") ~ "White")`.
Caused by error in `startsWith()`:
! non-character object(s)
Run `rlang::last_error()` to see where the error occurred.
Please check the below code with
adsldataframe.Here i am using the
ETHNICwithHISPANIC OR LATINOorNOT HISPANIC OR LATINOand i am creating a new column with all that starts withHISPasHISand all others as 'NON', just for exampleCreated on 2023-02-04 with reprex v2.0.2