I was helping my lab mate do this today.  I would look at ?extract

>From the help file:

library(raster)
r <- raster(ncol=36, nrow=18)
r[] <- 1:ncell(r)

###############################
# extract values with polygons
###############################
cds1 <- rbind(c(-180,-20), c(-160,5), c(-60, 0), c(-160,-60), c(-180,-20))
cds2 <- rbind(c(80,0), c(100,60), c(120,0), c(120,-55), c(80,0))
polys <- SpatialPolygons(list(Polygons(list(Polygon(cds1)), 1),
                              Polygons(list(Polygon(cds2)), 2)))

#plot(r)
#plot(polys, add=TRUE)
v <- extract(r, polys)
v

### for the mean
( m1 <- extract(r, polys, fun = mean) ) # argument fun to get the mean
( m2 <- unlist(lapply(v, function(x) if (!is.null(x)) mean(x, na.rm=TRUE)
else NA )) ) # or apply the function to the list


- Andrew

On Mon, Mar 24, 2014 at 2:55 PM, dododave <dododave@gmail.com> wrote:
Hi everyone.

I am trying to average NDVI values of a raster, but within a polygon. The
NDVI raster has pixel values between 0 and 255, and the polygon is an
irregular shape so I cannot simply use the extent function.

Any help appreciated!
Dave



--
View this message in context:
http://r-sig-geo.2731867.n2.nabble.com/NDVI-value-averaging-with-a-polygon-tp7586033.html
Sent from the R-sig-geo mailing list archive at Nabble.com.

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



-- 
Andrew P. Vitale
Masters Student
Department of Geography
University of Nevada, Reno
vitale232@gmail.com


On Mon, Mar 24, 2014 at 2:55 PM, dododave <dododave@gmail.com> wrote:

> Hi everyone.
>
> I am trying to average NDVI values of a raster, but within a polygon. The
> NDVI raster has pixel values between 0 and 255, and the polygon is an
> irregular shape so I cannot simply use the extent function.
>
> Any help appreciated!
> Dave
>
>
>
> --
> View this message in context:
> http://r-sig-geo.2731867.n2.nabble.com/NDVI-value-averaging-with-a-polygon-tp7586033.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
*Andrew P. Vitale*
Masters Student
Department of Geography
University of Nevada, Reno
vitale232@gmail.com

	[[alternative HTML version deleted]]

