Learn R Programming

container (version 0.3.0)

setS3: Set constructors

Description

The set is considered and implemented as a specialized container in which elements are always unique. It provides typical set operations such as union (+) and intersect (/).

Usage

set(x = list())

as.set(x)

is.set(x)

Arguments

x

(vector or list) initial elements of the set

S3 methods for class <code>Set</code>

add(x, elem)

If not already in set x, add elem.

See Also

container, Set, +.Set, /.Set, -.Set, <.Set, >.Set

Examples

Run this code
# NOT RUN {
s1 <- set(list(1, 2, "A", "B"))
s2 <- set(values(s1))
s1 == s2     # TRUE
s1$add(1)    # 1 was already in set, therefore ...
s1 == s2     # ... still TRUE
s1$add(3)
s1 == s2     # FALSE
s1 > s2      # TRUE
s1 - s2      # the added element
unlist(values(s1 / s2))

# }
# NOT RUN {
s1$remove(4)              # Error: 3 not in Set
# }

Run the code above in your browser using DataLab