R/allComb.R

Defines functions allComb

Documented in allComb

## this takes a classification vector
## with at least 2 levels
## and returns a model matrix with binary partitions
allComb <-
function(x, collapse)
{
    if (missing(collapse))
        collapse <-  getOption("ocoptions")$collapse
    f <- droplevels(as.factor(x))
    if (any(grepl(collapse, levels(f), fixed=TRUE)))
        stop("Collapse value found in levels.")
    LEVELS <- levels(f)
    i <- as.integer(f)
    n <- max(i)
    s <- seq_len(n)
    ac <- kComb(n)
    LABELS <- apply(ac, 2, function(z)
        paste(LEVELS[as.logical(z)], collapse=collapse))
    out <- apply(ac, 2, function(z) z[match(i, s)])
    rownames(out) <- f
    colnames(out) <- LABELS
    attr(out, "collapse") <- collapse
    attr(out, "comb") <- "all"
    #attr(out, "levels") <- LEVELS
    out
}

Try the opticut package in your browser

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

opticut documentation built on May 2, 2019, 5:09 a.m.