tags:

views:

47

answers:

2

Another rather basic question for which I can't find a definitive answer online:

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?

Thanks,

Roberto

+2  A: 

df[ df == "foo" ] = NA

c-urchin
I didn't know you could index a data frame that way!
JoFrhwld
+2  A: 

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"))
JoFrhwld