1

I have downloaded the 19 bioclimatic variables from Bioclim and I want to create a unique mask for all the 19 variables. The mask should exclude the pixels that have NA value in any of the 19 variables. This procedure is needed for further SDM analysis. I did this with a stack and worked, but it is not working for the Bioclim rasterBrick. In R:

library(raster
bioclim<-raster::getData('worldclim',var='bio', res=10)
s<-sum(bioclim)
MASK[!is.na(s)] <- 1
plot(MASK)
Gabriela
  • 21
  • 5
  • The content of `bioclim` in your code are not really numbers but objects of a class called `RasterStack`. Launch `summary(bioclim)` or `unclass(bioclim)` to take a look. What is it what you're trying to do? Have you taken a look to the object `RasterStack`? Thanks – lrnzcig Dec 16 '16 at 15:57
  • Hi, thanks, yes, bioclim is a rasterbrick. I am trying to sum the all the values of a pixel for the layers (bio1, bio2 etc) to end up with a single layer that contain values and NAs by using the sum function of raster package. Then I take the values and change for 1 so I have a mask of 1s and NAs. – Gabriela Dec 16 '16 at 19:01

1 Answers1

0

Sticking to your approach, your code worked for me after inserting one line to actually define the "MASK" object.

library(raster)
bioclim<-raster::getData('worldclim',var='bio', res=10)
s<-sum(bioclim)

# create MASK object with NA or other masking value
MASK <- setValues(s[[1]], NA)

MASK[!is.na(s)] <- 1
plot(MASK)

A little simpler, you could use:

MASK2 <- !is.na(s)
plot(MASK2)
joberlin
  • 321
  • 1
  • 4
  • Thank you very much, it worked. I used the first approach (changing values to 1) because latter in the analysis I needed to multiply by another layer. Cheers – Gabriela Dec 19 '16 at 12:38