[R] Sorting values within a raster

Sara Maxwell smaxwell at ucsc.edu
Thu Apr 21 21:23:26 CEST 2011

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  

Here is a sample dataset:

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

More information about the R-help mailing list