Given a TidySet merges several sets into the new one using the logic defined on FUN.
Usage
union(object, ...)
# S3 method for class 'TidySet'
union(
object,
sets,
name = NULL,
FUN = "max",
keep = FALSE,
keep_relations = keep,
keep_elements = keep,
keep_sets = keep,
...
)
Arguments
- object
A TidySet object.
- ...
Other named arguments passed to
FUN
.- sets
The name of the sets to be used.
- name
The name of the new set. By defaults joins the sets with an ∩.
- FUN
A function to be applied when performing the union. The standard union is the "max" function, but you can provide any other function that given a numeric vector returns a single number.
- keep
A logical value if you want to keep.
- keep_relations
A logical value if you wan to keep old relations.
- keep_elements
A logical value if you wan to keep old elements.
- keep_sets
A logical value if you wan to keep old sets.
Details
The default uses the max
function following the standard fuzzy definition, but it can be
changed. See examples below.
See also
Other methods that create new sets:
complement_element()
,
complement_set()
,
intersection()
,
subtract()
Other methods:
TidySet-class
,
activate()
,
add_column()
,
add_relation()
,
arrange.TidySet()
,
cartesian()
,
complement_element()
,
complement_set()
,
complement()
,
element_size()
,
elements()
,
filter.TidySet()
,
group_by.TidySet()
,
group()
,
incidence()
,
intersection()
,
is.fuzzy()
,
is_nested()
,
move_to()
,
mutate.TidySet()
,
nElements()
,
nRelations()
,
nSets()
,
name_elements<-()
,
name_sets<-()
,
name_sets()
,
power_set()
,
pull.TidySet()
,
relations()
,
remove_column()
,
remove_element()
,
remove_relation()
,
remove_set()
,
rename_elements()
,
rename_set()
,
select.TidySet()
,
set_size()
,
sets()
,
subtract()
Examples
# Classical set
rel <- data.frame(
sets = c(rep("A", 5), "B", "B"),
elements = c(letters[seq_len(6)], "a")
)
TS <- tidySet(rel)
union(TS, c("B", "A"))
#> Error in as.vector(x): no method for coercing this S4 class to a vector
# Fuzzy set
rel <- data.frame(
sets = c(rep("A", 5), "B", "B"),
elements = c(letters[seq_len(6)], "a"),
fuzzy = runif(7)
)
TS2 <- tidySet(rel)
# Standard default logic
union(TS2, c("B", "A"), "C")
#> Error in base::union(x, y, ...): unused argument ("C")
# Probability logic
union(TS2, c("B", "A"), "C", FUN = union_probability)
#> Error in base::union(x, y, ...): unused arguments ("C", FUN = function (p)
#> {
#> l <- length(p)
#> if (l == 1) {
#> return(p)
#> }
#> n <- vapply(seq_len(l)[-1], function(x) {
#> sum(combn(seq_along(p), x, FUN = independent_probabilities, p = p))
#> }, numeric(1))
#> sum(p) + sum(rep(c(-1, 1), length.out = length(n)) * n)
#> })