[R-sig-eco] adehabitat: Number of categories of each habitat

Clément Calenge clement.calenge at oncfs.gouv.fr
Tue Dec 16 13:23:22 CET 2008


Hello Roy,


> Apologies for asking such a simple question, but I have been having
> problems obtaining a simple summary of the habitat classes in a
> categorical (factor) asc map in the adehabitat library.  It has been
> created from overlaying an mcp polygon as follows:
>
> # Importation of asc files: factor e.g vegetation map
> (vegm <- paste("Y:/Map Import/veg05_7.asc", sep = "/")) # veg05_7 is a vegetation map with 10 classes
> (vegt <- paste("Y:/Map Import/veg05_2.txt", sep = "/")) # veg05 is a table with the names of the 10 classes
> veg <- import.asc(vegm, lev = vegt, type = "factor")
>
> # A Script to compute Homerange using Minimum Concex Polygon(MCP)
> roans<-read.csv("Y:/PhD Data/Data Analysis/Roan Data Analysis/Rawdata/NTO_G.csv") # Load the data
> xy<-roans[,c("X","Y")] # combine columns X & Y into a new column labelled xy
> id<-roans$Group # Allocate label id to Group column
> hrtg<-mcp(xy,id,percent=95) # Compute the homerange MCP
>
> ## Converts the home range to raster
> hrrast <- hr.rast(hrtg, veg)
>
> ## for each relocation, finds the values of the variables in x
> mcpveg = setmask(veg, hrrast)
>   

This line is incorrect (hrrast is an object of class "kasc", it should 
be of class "asc"), and useless since you redefine mcpveg below.


> hrrast2 = getkasc(hrrast, "Nyatoto Group")
> mcpveg = setmask(veg, hrrast2)
>   

At this point mcpveg is a *matrix* of class "asc".


> The asc map, mcpveg, produced by the final setmask function contains
> just the vegetation types within the MCP.  This map displays correctly.
> However, I'm unclear on how to obtain a numerical summary of the number
> of cells of each vegetation type, or percentage of each vegetation type,
> within the
> MCP.  Typing:
>
> summary(mcpveg)
>
> gives hundreds of columns, relating to the geographic structure of the
> asc map.
>   

Because mcpveg is a matrix, calling summary on it computes one summary 
per column of the matrix (which is not what you want). You should first 
convert it to vector. Try:

ta <- table(as.vector(mcpveg))
names(ta) <- levels(mcpveg)[as.numeric(names(ta))]
ta

HTH,


Clément Calenge

-- 
Clément CALENGE
Office national de la chasse et de la faune sauvage
Saint Benoist - 78610 Auffargis
tel. (33) 01.30.46.54.14



More information about the R-sig-ecology mailing list