Skip to content
Back to formatted view

Raw Message

Message-ID: <49479DBA.6080606@oncfs.gouv.fr>
Date: 2008-12-16T12:23:22Z
From: Clément Calenge
Subject: adehabitat: Number of categories of each habitat
In-Reply-To: <EMEW-kBFBL48449763452ff0de91b75354eb029efc1-1229426463.30173.5.camel@clarinet>

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