Very simple question but I can't find an answer anywhere. I have a dataframe with column 'foo' which contains "A", "B", "C", "D", "F", and so on.
I need to recode every value that is not "A" or "B" to NA.
The code below doesn't work because operations like that aren't possible for strings... how do I accomplish this for strings?
df[df$foo != "A" | "B"] <- NA