Skip to content
Prev 257661 / 398502 Next

Sorting values within a raster

I am working with a raster and want to take values assigned to each  
cell and sort them from largest to smallest, then cummulatively sum  
them together (in order from largest to smallest).  I'll then be  
coding the individual cells such that the top 10% of the largest cell  
values can be visualize with one color, the next 10% with another and  
so on.

I have tried a number of schemes but am having trouble figuring out  
how to chose the maximum value, code it and re-search the raster for  
the next highest value without replacement.  I am assuming this  
requires a loop, unless there is a function that will do this  
automatically.

Here is a sample dataset:

library(raster)
r <- raster(ncol=10, nrow=10)
values(r) <- runif(ncell(r))

Many thanks for any input,
Sara Maxwell
---------------------------------------------------
Sara M. Maxwell, Ph.D.
UC Santa Cruz