[r] replacing NA's with 0's in R dataframe

I've been playing around with the airquality dataset in R and figuring out how to remove lines with missing values. I used the following command:

complete.cases(airquality)
AQ1<-airquality[complete.cases(airquality),]

How do I go about replacing the NA's in airquality with 0's and then creating a new dataframe, AQ2?

P.S. Does my command above create a new dataframe called AQ1?

Thanks

This question is related to r

The answer is


What Tyler Rinker says is correct:

AQ2 <- airquality
AQ2[is.na(AQ2)] <- 0

will do just this.

What you are originally doing is that you are taking from airquality all those rows (cases) that are complete. So, all the cases that do not have any NA's in them, and keep only those.


Here are two quickie approaches I know of:

In base

AQ1 <- airquality
AQ1[is.na(AQ1 <- airquality)] <- 0
AQ1

Not in base

library(qdap)
NAer(airquality)

PS P.S. Does my command above create a new dataframe called AQ1?

Look at AQ1 and see