Replacing character values with NA in a data frame

Roberto picture Roberto · Jul 28, 2010 · Viewed 91.5k times · Source

I have a data frame containing (in random places) a character value (say "foo") that I want to replace with a NA.

What's the best way to do so across the whole data frame?

Answer

c-urchin picture c-urchin · Jul 28, 2010

This:

df[ df == "foo" ] <- NA