already found a bug with bursts containing 2 data points... here is a code
corrected:
mindistkeep2 <- function(x, threshold)
{
if (!inherits(x,"ltraj"))
stop("x should be of class 'ltraj'")
foo <- function(y) {
ul <- 1
if (nrow(y) > 2){
for (i in 2:nrow(y)) {
if(y$dist[i-1]<threshold){
ul[i]= ul[i-1]
y$dist[i] = sqrt( (y$x[i+1] -y$x
[ul[i]])*(y$x[i+1] -y$x [ul[i]])+(y$y[i+1]
-y$y [ul[i]])*(y$y[i+1] -y$y [ul[i]]) )
} else ul[i]={i}
}
} else print(nrow (y))
if (!is.null(attr(y, "infolocs"))) {
infol <- attr(y, "infolocs")
}
z <- y[ul,c("x","y")]
da <- y$date
if (!is.null(attr(y, "infolocs"))) {
infol <- attr(y, "infolocs")
lt <- as.ltraj(z, da, id=attr(y,"id"), burst=attr(y,"burst"),
typeII=attr(x,"typeII"), infolocs=infol)
} else {
lt <- as.ltraj(z, da, id=attr(y,"id"), burst=attr(y,"burst"),
typeII=attr(x,"typeII"))
}
return(lt)
}
res <- do.call("c.ltraj", lapply(x, foo))
class(res) <- c("ltraj","list")
return(res)
}
_______________________________________________
AniMov mailing list
[email protected]
http://lists.faunalia.it/cgi-bin/mailman/listinfo/animov