I have a data frame and some columns have NA values.
NA
How do I replace these NA values with zeroes?
You can use replace()
replace()
For example:
> x <- c(-1,0,1,0,NA,0,1,1) > x1 <- replace(x,5,1) > x1 [1] -1 0 1 0 1 0 1 1 > x1 <- replace(x,5,mean(x,na.rm=T)) > x1 [1] -1.00 0.00 1.00 0.00 0.29 0.00 1.00 1.00