Replacing character values with NA in a data frame
This:
df[ df == "foo" ] <- NA
One way to nip this in the bud is to convert that character to NA when you read the data in in the first place.
df <- read.csv("file.csv", na.strings = c("foo", "bar"))