I have simple question: given a bounding box, how can I count the number of specific values (say, I am interested in the number of
value == 1 ) in a raster in 1) arcpy, or 2) raster package in R?
As an example, let's create a 1 degree grid covering the globe:
The bounding box is converted to an
Having done that, tabulation is straightforward:
In this output the first row lists the values and the second lists their corresponding counts:
As a check we can plot the raster and the extent:
A minor addition: you could also use (memory-safe) function "freq":
Following the answer by whuber:
But now do:
It only matters for very large objects (raster on file). 'freq' returns a two-column matrix (value/count) whereas 'table' returns a table.