[snip]
I am trying to select only a part of the trajectory stored in this ltraj
class object, following an example from Calenge in the package
'adehabitatLT':
lim <- as.POSIXct(strptime(c("28/05/2010 02:00:40", "30/06/2010 02:00:41"),
"%d/%m/%Y %H:%M:%S"))
ltrj.bis <- gdltraj(ltrj.obj, min=lim[1], max=lim[2], type="POSIXct" )
but for some reasons it does not work properly. I got this error message
that I do not understand:
Error in `[.default`(res, , names(res) %in% which, drop = FALSE) :
number of dimensions incorrect
Anyone has an idea about why it doesn't work?
You have identified a bug in the function gdltraj. I have corrected this
bug and uploaded a new version of the package to CRAN. It will be
available soon. Meanwhile, you can use this function instead:
gdltraj <- function (x, min, max, type = c("POSIXct", "sec", "min", "hour",
"mday", "mon", "year", "wday", "yday"))
{
if (!inherits(x, "ltraj"))
stop("x should be of class \"ltraj\"")
if (!attr(x, "typeII"))
stop("x should be of type II (time recorded)")
type <- match.arg(type)
if (type == "POSIXct") {
x <- lapply(x, function(y) {
infol <- attr(y, "infolocs")
if (!is.null(infol))
infol <- infol[(y$date > min) & (y$date < max),
, drop=FALSE]
y <- y[(y$date > min) & (y$date < max), ]
if (!is.null(infol))
attr(y, "infolocs") <- infol
return(y)
})
}
else {
x <- lapply(x, function(y) {
da <- as.POSIXlt(y$date)[[type]]
infol <- attr(y, "infolocs")
if (!is.null(infol))
infol <- infol[(da >= min) & (da < max), ,drop=FALSE]
y <- y[(da >= min) & (da < max), ]
if (!is.null(infol))
attr(y, "infolocs") <- infol
return(y)
})
}
if (all(sapply(x, nrow) == 0))
stop("No relocations within the specified interval")
x[sapply(x, nrow) == 0] <- NULL
class(x) <- c("ltraj", "list")
attr(x, "typeII") <- TRUE
attr(x, "regular") <- is.regular(x)
x <- rec(x)
return(x)
}
HTH
Clément Calenge
--
Clément CALENGE
Cellule d'appui à l'analyse de données
Direction des Etudes et de la Recherche
Office national de la chasse et de la faune sauvage
Saint Benoist - 78610 Auffargis
tel. (33) 01.30.46.54.14
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology