Nevil,

You can use the freq function. After running the example I gave you can do

sapply(lst, freq)

or

freq(s[[1]])
freq(s[[2]])
etc.

(which is equivalent to  table(values(s[[1]]))  etc.)

Robert


On Tue, Sep 6, 2011 at 7:20 PM, Nevil Amos <nevil.amos@gmail.com> wrote:

>  Thanks
> the second thing the Region Group does is to count the number of cells in
> each contiguous area  can I also acheive this in Raster?
>
>
> On 7/09/2011 10:48 AM, Robert J. Hijmans wrote:
>
> Nevil,
> The function 'clump' in 'raster' does this for a single value and perhaps
> you can use it in a loop over all values to achieve what you are after.
> Robert
>
>   library(raster)
> r <- raster(ncol=10, nrow=10)
> r[] <- round(runif(100)*3)
> u <- unique(r)
> lst <- list()
> for (i in 1:length(u)) {
>  x <- r==u[i]
>  # or, for large files:
>  # x <- calc(r, function(x) x == u[i])
>  lst[[i]] <- clump(x)
> }
> s <- stack(lst)
> layerNames(s) <- u
> plot(s)
>
>
>
>
>
>  On Mon, Sep 5, 2011 at 8:52 PM, Nevil Amos <nevil.amos@gmail.com> wrote:
>
>> Is there an equivalent of the ESRI spatial analyst "Region group"  command
>> in one of the r packages that handles rasters
>>
>> ie function that assigns a unique id all cells of a contiguous area of the
>> same value
>>
>> Thanks
>>
>> Nevil amos
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
>

	[[alternative HTML version deleted]]

