I am new in R. How can I replace NA's with 0 for my raster data which have spatial information?
The answer from Wilfried Thuiller in R-SIG-Geo mailing list works:
#getting a raster
library(raster)
f <- system.file("external/test.grd", package="raster")
f
r <- raster(f) #r is the object of class 'raster'.
# replacing NA's by zero
r[is.na(r[])] <- 0
-
(+1) You can find many examples of this much closer to home simply by searching our site: gis.stackexchange.com/search?q=is.na%28. For example, you will find your solution implemented in the code at gis.stackexchange.com/a/58911. – whuber Jul 23 '13 at 17:30