set-operations.Rd
Set operations for gRbase and related packages.
maximal_sets(setlist, index = FALSE)
minimal_sets(setlist, index = FALSE)
remove_redundant(setlist, maximal = TRUE, index = FALSE)
is_inset(x, setlist, index = FALSE)
filter_maximal_vectors(setlist, index = FALSE)
get_subset(x, setlist, all = FALSE)
get_superset(x, setlist, all = FALSE)
is_subsetof(set, set2)
is.subsetof(x, set)
subsetof(x, set)
'setlist' is a list of vectors representing a set of subsets; i.e. V1,...VQ where Vk is a subset of some base set V.
'all' If true, get_superset
will return index of all
vectors containing the element; otherwise only the first index is
returned.
is_inset
: Checks if the set
x is in one of the Vk's.
remove_redundant
: Returns those Vk which are not contained
in other subsets; i.e. gives the maximal sets. If maximal is FALSE
then returns the minimal sets; i.e. Vk is returned if Vk is
contained in one of the other sets Vl and there are no set Vn
contained in Vk.
Notice that the comparisons are made by turning the elements into characters and then comparing these. Hence 1 is identical to "1".
set <- list(c(1, 2), c(1, 2, 3), c(2, 3, 6), c(2, 4), c(5, 6), 5)
el1 <- c(2, 1)
el2 <- c(2, 3)
el3 <- c(4, 3)
el4 <- c(2, 1, 3)
maximal_sets(set)
#> [[1]]
#> [1] 1 2 3
#>
#> [[2]]
#> [1] 2 3 6
#>
#> [[3]]
#> [1] 2 4
#>
#> [[4]]
#> [1] 5 6
#>
minimal_sets(set)
#> [[1]]
#> [1] 5
#>
#> [[2]]
#> [1] 1 2
#>
#> [[3]]
#> [1] 2 4
#>
#> [[4]]
#> [1] 2 3 6
#>
remove_redundant(set)
#> [[1]]
#> [1] 1 2 3
#>
#> [[2]]
#> [1] 2 3 6
#>
#> [[3]]
#> [1] 2 4
#>
#> [[4]]
#> [1] 5 6
#>
remove_redundant(set, maximal=FALSE)
#> [[1]]
#> [1] 5
#>
#> [[2]]
#> [1] 1 2
#>
#> [[3]]
#> [1] 2 4
#>
#> [[4]]
#> [1] 2 3 6
#>
is_inset(el1, set)
#> [1] TRUE
is_inset(el2, set)
#> [1] TRUE
is_inset(el3, set)
#> [1] FALSE
get_subset(el1, set)
#> [1] 1
get_subset(el1, set)
#> [1] 1
get_subset(el2, set)
#> integer(0)
get_subset(el3, set)
#> integer(0)
get_superset(el1, set)
#> [1] 1
get_superset(el1, set, all=TRUE)
#> [1] 1 2
get_superset(el2, set)
#> [1] 2
get_superset(el3, set)
#> integer(0)
is_subsetof(el1, el1)
#> [1] TRUE
is_subsetof(el1, el2)
#> [1] FALSE
is_subsetof(el1, el4)
#> [1] TRUE