I am working with a column of employment data. I want to end with the following values:
- Unemployed
- Retired
- Self-employed
- Disabled
- Employed
I have cleaned up all the different iterations of all the values except for employed. I am trying to craft a statement that would do something along the lines of:
If not in this list "Unemployed | Retired | Self-Employed | Disabled" change value to "Employed".
I have been attempting the use of the %notin% function and the replace() function but am missing something. Any help pointing me in the correct direction would be greatly appreciated.
UPDATE/EDIT:
I got code to work based on the suggestion from @Rui Barradas, but when cleaning up and notating the code I broke something and I can't for the life of me figure out what I am doing wrong. The code below does not throw an error but it is not changing the values to 'Employed' when I verify with table(df7$patient_employment)
`%notin%` <- Negate(`%in%`)
x <- c(df7$patient_employment, "Unemployed", "Retired", "Self-Employed", "Disabled")
x[x %notin% df7$patient_employment] <- "Employed"
RESOLVED:
After some additional help it was pointed out that I was utilizing x
from the example when I should have been utilizing my data names. Being working on this for too long. Time to stretch my legs. Thank you @Rui Barradas