[R] lapply and kernelUD (adehabitatHR package): Home Range kernel estimation for a list of individuals

nymphita sandrablazquezcabrera at gmail.com
Tue Oct 30 21:51:25 CET 2012


Dear R experts,

I'm using the adehabitatHR package in order to perform a kernel analysis and
estimate the home range of my input data (GPS relocations of 42
individuals).
I've done the analysis for one of the individuals and it worked perfectly
(see code below).

But now I'm trying to use a list and call the function lapply to do the same
thing through all the 42 individuals (also see code below), but I'm only
obtaining this error:
Error in seq.default(yli[1], yli[2], by = diff(xg[1:2])) : 
  invalid (to - from)/by in seq(.)

I have browsed the net in order to find out what does it mean, but I haven't
found a similar error, so I'm stuck with it...
Any thoughts on what I could be doing wrong will be very appreciated!


See below the code:
FOR ONE ANIMAL NAMED "Gael". IT WORKED PERFECTLY!

># Read a shapefile and convert it into a SpatialPointsDataFrame with its
corresponding CRS
>Gael_WGS84_WorldM <- readShapePoints("900_Gael_WGS84_WorldM", 
                proj4string=CRS("+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0
+ellps=WGS84 +datum=WGS84 +units=m +no_defs"))

># Remove all the columns except the name of the animal to use the kernelUD
function. My data looks like this:
> head(Gael_WGS84_WorldM[-c(2:25)])
         coordinates Name
0 (-683614, 4459280) Gael
1 (-769563, 4516660) Gael
2 (-721607, 4431310) Gael
3 (-683613, 4459290) Gael
4 (-765266, 4502750) Gael
5 (-683602, 4459280) Gael
Coordinate Reference System (CRS) arguments: +proj=merc +lon_0=0 +k=1
+x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs
+towgs84=0,0,0 

>#  Href Fixed Kernel Density Estimator
>K_Gael_estUDm <- kernelUD(Gael_WGS84_WorldM[-c(2:25)], h="href", grid=500,
kern="bivnorm")

FOR THE LIST OF ANIMALS. EVERYTHING SEEMS TO WORK FINE UNTIL I CALL THE
lapply FUNCTION, THEN IT GIVES AN ERROR:

> # Create a list (vector) with all the animal shapefiles in my folder
> AnimalShapeList <- list.files(path=".", pattern="WGS84_WorldM.shp")

>Animals <- lapply(AnimalShapeList, readShapePoints, 
+           proj4string=CRS("+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0
+ellps=WGS84 +datum=WGS84 +units=m +no_defs"))

> # Create a list of elements with only the coordinates (removing columns
> 2:25). 
> AnimalsXY <- lapply(Animals, "[", TRUE, -c(2:25))

>K_estUDm <- lapply(AnimalsXY, kernelUD, h="href", grid=20, kern="bivnorm")
Error in seq.default(yli[1], yli[2], by = diff(xg[1:2])) : 
  invalid (to - from)/by in seq(.)



--
View this message in context: http://r.789695.n4.nabble.com/lapply-and-kernelUD-adehabitatHR-package-Home-Range-kernel-estimation-for-a-list-of-individuals-tp4647934.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list