R/split_shape.R

Defines functions split_shape

# similar to sp::split, but works different for SpatialPoints
split_shape <- function(x, f, drop=TRUE, ...) {
    if (!is.factor(f)) {
        warning("f is not a factor", call. = FALSE)
        f <- as.factor(f)
    }
    lev <- if (drop) {
        intersect(levels(f), f)
    } else levels(f)
    xlist <- lapply(lev, function(l) {
        ids <- which(f==l)
        if (length(ids)==0L) NULL else x[ids,]
    })
    names(xlist) <- lev
    xlist
}

Try the tmaptools package in your browser

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

tmaptools documentation built on Jan. 20, 2021, 1:07 a.m.