cset | R Documentation |
Creation and manipulation of customizable sets.
cset(gset,
orderfun = sets_options("orderfun"),
matchfun = sets_options("matchfun"))
cset_support(x)
cset_core(x, na.rm = FALSE)
cset_peak(x, na.rm = FALSE)
cset_height(x, na.rm = FALSE)
cset_memberships(x, filter = NULL)
cset_universe(x)
cset_bound(x)
cset_transform_memberships(x, FUN, ...)
cset_concentrate(x)
cset_dilate(x)
cset_normalize(x, height = 1)
cset_defuzzify(x,
method = c("meanofmax", "smallestofmax",
"largestofmax", "centroid"))
matchfun(FUN)
cset_orderfun(x)
cset_matchfun(x)
cset_orderfun(x) <- value
cset_matchfun(x) <- value
as.cset(x)
is.cset(x)
cset_is_empty(x, na.rm = FALSE)
cset_is_subset(x, y, na.rm = FALSE)
cset_is_proper_subset(x, y, na.rm = FALSE)
cset_is_equal(x, y, na.rm = FALSE)
cset_contains_element(x, e)
cset_is_set(x, na.rm = FALSE)
cset_is_multiset(x, na.rm = FALSE)
cset_is_fuzzy_set(x, na.rm = FALSE)
cset_is_set_or_multiset(x, na.rm = FALSE)
cset_is_set_or_fuzzy_set(x, na.rm = FALSE)
cset_is_fuzzy_multiset(x)
cset_is_crisp(x, na.rm = FALSE)
cset_has_missings(x)
cset_cardinality(x, type = c("absolute", "relative"), na.rm = FALSE)
cset_union(...)
cset_mean(x, y, type = c("arithmetic", "geometric", "harmonic"))
cset_product(...)
cset_difference(...)
cset_intersection(...)
cset_symdiff(...)
cset_complement(x, y)
cset_power(x)
cset_cartesian(...)
cset_combn(x, m)
## S3 method for class 'cset'
cut(x, level = 1, type = c("alpha", "nu"), strict = FALSE, ...)
## S3 method for class 'cset'
mean(x, ..., na.rm = FALSE)
## S3 method for class 'cset'
## median(x, na.rm = FALSE, ...) [R >= 3.4.0]
## median(x, na.rm) [R < 3.4.0]
## S3 method for class 'cset'
length(x)
## S3 method for class 'cset'
lengths(x, use.names = TRUE)
x |
For |
y |
A (c)set object. |
gset |
A generalized set (or some other R object coercible to it). |
matchfun |
A function for matching similar elements, comparable
to |
FUN |
A predicate testing for equality of two objects. |
orderfun |
A function taking a list and returning an integer vector, specifying the order in which an iterator processes the set elements. Alternatively, the index vector can be specified directly. |
value |
A new match function (order function). |
type |
For |
strict |
Logical indicating whether the cut level must be exceeded strictly (“greater than”) or not (“greater than or equal”). |
height |
Double from the unit interval for scaling memberships. |
e |
An object of class |
filter |
Optional vector of elements to be filtered. |
m |
Number of elements to choose. |
method |
Currently, only |
level |
The minimum membership level. |
use.names |
logical; should the names of |
na.rm |
logical indicating whether |
... |
For |
Customizable sets extend generalized sets in two ways: First, users
can control the way elements are matched, i.e., define equivalence
classes of elements. Second, an order function (or permutation index)
can be specified for each set for changing the order in which
iterators such as as.list
process the elements. The latter in
particular influences the labeling and print methods for
customizable sets.
The match function needs to be vectorized in a similar way than
match
. matchfun
can be used to create such a
function from a “simple” predicate testing for equality
(such as, e.g., identical
). Make sure, however, to
create the same function only once.
Note that operations on customizable sets require the same match function for all sets involved. The order function can differ, but will then be stripped from the result.
sets_options
can be used to
conveniently switch the default match and/or
order function if a number of cset
objects need to be created.
D. Meyer and K. Hornik (2009), Generalized and customizable sets in R, Journal of Statistical Software 31(2), 1–27. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v031.i02")}.
set
for (“ordinary”) sets,
gset
for generalized sets,
cset_outer
, and
tuple
for tuples (“vectors”).
## default behavior of sets: matching of elements is very strict
## Note that on most systems, 3.3 - 2.2 != 1.1
x <- set("1", 1L, 1, 3.3 - 2.2, 1.1)
print(x)
y <- set(1, 1.1, 2L, "2")
print(y)
1L %e% y
set_union(x, y)
set_intersection(x, y)
set_complement(x, y)
## Now use the more sloppy match()-function.
## Note that 1 == "1" == 1L ...
X <- cset(x, matchfun = match)
print(X)
Y <- cset(y, matchfun = match)
print(Y)
1L %e% Y
cset_union(X, Y)
cset_intersection(X, Y)
cset_complement(X, Y)
## Same using all.equal().
## This is a non-vectorized predicate, so use matchfun
## to generate a vectorized version:
FUN <- matchfun(function(x, y) isTRUE(all.equal(x, y)))
X <- cset(x, matchfun = FUN)
print(X)
Y <- cset(y, matchfun = FUN)
print(Y)
1L %e% Y
cset_union(X, Y)
cset_intersection(X, Y)
cset_complement(X, Y)
### change default functions via set_option
sets_options("matchfun", match)
cset(x)
cset(y)
cset(1:3) <= cset(c(1,2,3))
### restore package defaults
sets_options("matchfun", NULL)
### customized order function
FUN <- function(x) order(as.character(x), decreasing = TRUE)
Z <- cset(letters[1:5], orderfun = FUN)
print(Z)
as.character(Z)
## converter for ordered factors keeps order
o <- ordered(c("a", "b", "a"), levels = c("b", "a"))
as.set(o)
as.cset(o)
## converter for other data types keep order if the elements are unique:
as.cset(c("A", "quick", "brown", "fox"))
as.cset(c("A", "quick", "brown", "fox", "quick"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.