R/mindistkeep.r

Defines functions mindistkeep

Documented in mindistkeep

mindistkeep <- function(x, threshold)
{
    if (!inherits(x,"ltraj"))
        stop("x should be of class 'ltraj'")
    foo <- function(y) {
        ul <- 1
        for (i in 2:nrow(y))
            ul[i] <- ifelse(y$dist[i-1]<threshold,ul[i-1],i)
        z <- y[ul,c("x","y")]
        da <- y$date
        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)
}

Try the adehabitat package in your browser

Any scripts or data that you put into this service are public.

adehabitat documentation built on Jan. 28, 2018, 5:02 p.m.