thanks, robert... i'm not sure what was going on either, but upgrading from
raster v1.3-x helped!

fyi, i forgot to mention in the previous post that i created my mask by
selecting an individual cell value from an imported raster (e.g. 'm1'
below). using this process with new raster package, cell values that don't
meet the '==' condition get returned as '0', so i just reclass 0s to NAs in
my mask, and then the 'mask' function drops those NAs onto my output grid as
desired...

best, j



> r     <- raster("sdm.asc")
> m   <- raster("mask.asc")
> m1 <- m == 1
> r1   <- mask(r, m1)
>
> na       <- c(-Inf,0,NA, 1,1,1)
> m1.na <- reclass(m1, na)
> r1.na   <- mask(r, m1.na)
>
> count(r,  NA)
[1] 20533362
> count(m1, NA)
[1] 20533362
> count(r1, NA)
[1] 20533362
> count(m1.na, NA)
[1] 39269328
> count(r1.na, NA)
[1] 39269328






On Thu, Sep 23, 2010 at 4:29 PM, Robert J. Hijmans <r.hijmans@gmail.com>wrote:

> Hi Jason,
>
> count(mr, NA) should indeed be larger than or equal to count(m, NA);
> as in the example below. No idea what is going on in your case. What
> makes you say that the values are returned at zeros? Are you using an
> old version? If not, could you send me the files?
>
> Robert
>
> > library(raster)
> Loading required package: sp
> raster version 1.5-9 (21-September-2010)
> >
> > r = raster(ncol=10, nrow=10)
> > r[] = round(runif(ncell(r))*2)
> > m = raster(ncol=10, nrow=10)
> > m[] = round(runif(ncell(m)))
> > r[r==0] <- NA
> > m[m==0] <- NA
> >
> > mr <- mask(r, m)
> >
> > count(r, NA)
> [1] 20
> > count(m, NA)
> [1] 51
> > count(mr, NA)
> [1] 59
>
>
> On Thu, Sep 23, 2010 at 12:44 PM, Jason MacKenzie <jmackenzie@tnc.org>
> wrote:
> > dear list members
> >
> > i want to create a new raster where all cells that are NA in my 'mask'
> are
> > set to NA, but all other values stay the same as input rasters. instead
> of
> > NAs, masked areas are getting returned as 0s (see counts below). am i
> > missing a flag to set NAs?
> >
> > thanks in advance,
> > j
> >
> >
> >
> > r    <- raster(raster.asc)
> > m  <- raster(mask.asc)
> > mr <- mask(r, m)
> >
> >> count (r, NA)
> > [1] 20533362
> >> count (m, NA)
> > [1] 39269328
> >> count (mr, NA)
> > [1] 20533362
> >
> >
> >
> >
> >
> > --
> >
> > *Jason MacKenzie, PhD*
> > *
> > Climate Change Adaptation Fellow*
> > The Nature Conservancy
> > 201 Mission Street, 4th Floor
> > San Francisco, CA 94105
> > jmackenzie@tnc.org
> >
> > (415) 281 0472            [work]
> > (415) 777 0244            [fax]
> > (510) 717 1544            [cell]
> > jasonbmackenzie        [skype]
> >
> >        [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@stat.math.ethz.ch
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>

	[[alternative HTML version deleted]]

