[R-sig-Geo] Clipping grid using shapefile?

Christopher Swingley cswingle at gmail.com
Mon Mar 1 21:48:02 CET 2010


> I tried something like this:
> 
>     > clip <- overlay(ppt01, vector[vector$SITECODE=='A-001',])
> 
> and got:
> 
>     > summary(clip)
>      Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's
>       1        1        1        1        1        1   20199300
>     > mean(clip, na.rm = TRUE)
>      [1] 1
>     > clip[!is.na(clip)]
>      [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Sorry to reply to my own post, but now that I think about this, it looks
like 'clip' is a raster containing 1's where there's data and NA where
there isn't.  This makes me think that something like this:

    > mean(ppt01[clip,], na.rm = TRUE)

would give me the mean that I want.  Unfortunately, I get this:

    *** caught segfault ***
    address 0x7f626f27c758, cause 'memory not mapped'

    Traceback:
     1: ppt01[clip, ]
     2: mean(ppt01[clip, ], na.rm = TRUE)

Is there a more memory efficient way to do this, especially since I'm
dealing with 15 data points out of 20,199,315?

Thanks,

Chris
-- 
Christopher S. Swingley
http://swingleydev.com/
<cswingle at gmail.com>



More information about the R-sig-Geo mailing list