In R I have a stack (nsw.stack) which contains 6 variables. I have clipped the extent. However, When I look at the summary it appears that there is a lot of NA values (see below). I think this is slowing down the computing power when i do a raster prediction. (right?)

If so, how do I get rid of the NA.values from the rasters prior to using the predict code, or is there a way to ignore the NA values while predicting.

> summary(nsw.stack)
                 riv         lake         ndvi    temp    prec     dem
Min.    0.000000e+00 0.000000e+00      -0.0960     -14     114      -4
1st Qu. 2.640341e-02 7.969768e-02       0.2328      29     162     134
Median  7.040909e-02 1.814401e-01       0.3288      49     219     226
3rd Qu. 1.814401e-01 3.925149e-01       0.4128      75     297     338
Max.    1.120824e+00 1.613323e+00       0.7176     115     406    1281
NA's    2.103107e+06 2.103674e+06 2103309.0000 2103188 2103188 2103188
Warning message:
In .local(object, ...) :
  summary is an estimate based on a sample of 1e+05 cells (2.47% of all cells)
  • Turns out you are not meant to remove the NA's. You need them in this situation. – I.Stirs Jun 21 '16 at 13:26

If you have NA values that indicates that for a given raster they may not have a value at that particular location. There is a very thorough answer here on the topic You may want to ensure that you have cropped and masked your rasters before doing any future analysis. In R, you can change the NA values to a value to visualize where these NA values are and what could be going on with your data. If you choose, you could also remove them. There's another great example here with visualization of NA values.

nsw.stack[is.na(nsw.stack)] <- 999
| improve this answer | |

The raster package function predict() has an na.rm option. I think that would be the best way to address this problem.

| improve this answer | |

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.