Learn R Programming

set6 (version 0.1.1)

Set: Mathematical Set

Description

A general Set object for mathematical sets. This also serves as the parent class to intervals, tuples, and fuzzy variants.

Value

R6 object of class Set.

Constructor

Set$new(..., universe = UniversalSet$new(), elements = NULL, class = NULL)

Constructor Arguments

Argument Type Details
... ANY Elements in the set.
universe Set Universe that the Set lives in, default is the UniversalSet.
elements list Alternative constructor that may be more efficienct if passing objects of multiple classes.
class character Optional string naming a class that if supplied gives the set the typed property.

Constructor Details

Sets are constructed by elements of any types (including R6 classes), excluding lists. Sets should be used within Sets instead of lists. The universe argument is useful for taking the absolute complement of the Set. If a universe isn't given then UniversalSet is assumed. If the class argument is non-NULL, then all elements will be coerced to the given class in construction, and if elements of a different class are added these will either be rejected or coerced.

Public Fields

Field Link

class class elements elements length length lower lower upper upper max max min min range range properties properties traits traits type type

Public Methods

Comparison Methods Link contains(x, all = FALSE, bound = NULL) contains equals(x, all = FALSE) equals isSubset(x, proper = FALSE, all = FALSE) isSubset Representation Methods Link strprint(n = 2) strprint print(n = 2) print summary(n = 2) summary

Details

Mathematical sets can loosely be thought of as a collection of objects of any kind. The Set class is used for sets of finite elements, for infinite sets use Interval. These can be expanded for fuzzy logic by using FuzzySets. Elements in a set cannot be duplicated and ordering of elements does not matter, Tuples can be used if duplicates or ordering are required.

See Also

Other sets: ConditionalSet, FuzzySet, FuzzyTuple, Interval, Tuple, UniversalSet

Examples

Run this code
# NOT RUN {
# Set of integers
Set$new(1:5)

# Set of multiple types
Set$new("a", 5, Set$new(1))

# Each Set has properties and traits
s = Set$new(1,2,3)
s$traits
s$properties

# Elements cannot be duplicated
Set$new(2, 2) == Set$new(2)

# Ordering does not matter
Set$new(1, 2) == Set$new(2, 1)

# }

Run the code above in your browser using DataLab