Skip to content
Prev 22754 / 29559 Next

summing rasters with a condition given by other rasters

Hi,
On May 10, 2015, at 7:37 AM, Martin Brandt <martin.brandt at mailbox.org> wrote:

            
Yes, as tempting as it is to do otherwise you really do have to use numeric position indices.  Inside the function sum_segment the value of x is simple a numeric vector. Within the scope of the function the context of the pixels embedded in the raster object is temporarily "lost" - they are just a vector of numbers.  

To work with the calc() function you must first compute the position indices for sos and eos using which().

sos <- which(names(b) == "blue.1")  # you would substitue the name of your layer for blue.1
eos <- which(names(b) == "green.3") # and again for green.3

Cheers,
Ben
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org