Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (5.3k points)

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

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

1 Answer

0 votes

To replace character values in a data frame with NA, you can use the following syntax:

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

Note that if you were trying to replace NA with "foo", the reverse will not work

 (df[ df == NA ] = "foo") 

You would need to use 

df[] <- "foo"

If you want to explore more in R programming then watch this R programming tutorial for beginner:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories