I have been struggling with something seemingly straightforward for several days now, and am hoping for some assistance. 

I have calculated the area for cells within a raster, and now want to extract the area for specific cells and sum the area of those cells together.  I have tried a number of functions such as stackSelect, but think I have had trouble using the proper syntax in my logical statements. I am new to the raster package, however, so this may be my issue.

For example, if I have data that looks like this:

require(raster)

r <- raster(ncol=10, nrow=10)
r[]=1:ncell(r)
t <- area(r)
s <- stack(r, t)

for all values in first layer of s (equivalent to the raster r) with the values 50 and 75, I want to take the corresponding values in the second layer (equivalent to t), create a new raster (call it 'z') where the remaining cells are given a value of 0 (or NA) and finally sum the values of the z.  

Any suggestions appreciated.
Thank you, 
Sara


	[[alternative HTML version deleted]]

