Adding a "0/1" factor based on another variable -- Doing a proper reprex

dplyr::case_when would be a good choice for this. The way to use this is like so:

data %>% 
    mutate(
        newvar = case_when(
            x == y ~ 'result1',
            x != y ~ 'result2'
        )
    )

If you are able to provide a reprex of your data, we can help you dig into extracting the e and c characters.

1 Like