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
f <- system.file("external/test.grd", package="raster")
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.