R/combn.R

Defines functions cset_combn gset_combn set_combn

Documented in cset_combn gset_combn set_combn

set_combn <-
function(x, m)
{
    if (m == 0)
        set()
    else
        do.call(set, apply(combn(.as.list(x), m), 2L, as.set))
}

gset_combn <-
function(x, m)
{
    if (m == 0L)
        gset()
    else {
        support <- apply(combn(.as.list(x), m), 2L, as.set)
        memberships <- unlist(apply(combn(.get_memberships(x), m), 2L, list),
                              recursive = FALSE)
        do.call(set, Map(gset, support, memberships))
    }
}

cset_combn <-
function(x, m)
{
    ## get matchfun and orderfun
    matchfun <- .matchfun(x)
    orderfun <- .orderfun(x)
    if (is.integer(orderfun))
        orderfun <- NULL

    if (m == 0L)
        gset()
    else {
        support <- apply(combn(.as.list(x), m), 2L, as.set)
        memberships <- unlist(apply(combn(.get_memberships(x), m), 2L, list),
                              recursive = FALSE)
        do.call(set,
                lapply(Map(gset, support, memberships),
                       cset, orderfun, matchfun)
                       )
    }
}

Try the sets package in your browser

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

sets documentation built on March 7, 2023, 7:58 p.m.