9

I am new in R. How can I replace NA's with 0 for my raster data which have spatial information?

16

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 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.