SetS3 {container} | R Documentation |
Set and ordered Set
Description
The Set is considered and implemented as a specialized
Container, that is, Set
elements are always unique. It provides
typical set operations such as union
and intersect
.
Usage
setnew(..., .ordered = FALSE)
as.set(x)
as.orderedset(x)
is.set(x)
is.orderedset(x)
Arguments
... |
initial elements put into the |
.ordered |
|
x |
|
Details
Methods that alter Set objects usually come in two versions
providing either copy or reference semantics where the latter start with
'ref_'
to note the reference semantic, for example, add()
and ref_add()
.
-
setnew(...)
initializes and returns aSet()
object.
-
as.set(x)
coercesx
to a set.
-
as.orderedset(x)
coercesx
to an ordered set.
-
is.set(x)
returnsTRUE
ifx
is of classSet
andFALSE
otherwise.
-
is.orderedset(x)
returnsTRUE
ifx
is of classOrderedSet
andFALSE
otherwise.
-
x
&
y
performs the set intersection of x and y
-
x
|
y
performs the set union of x and y
See Also
See container()
for all inherited methods. For the full class
documentation see Set and it's superclass Container.
Examples
s = setnew(1, b = NA, 1:3, c = container("a", 1))
is.set(s)
print(s)
length(s)
names(s)
as.list(s)
unpack(s) # flatten recursively similar to unlist
so = setnew(2, 1, .ordered = TRUE)
print(so)
add(so, 0)
# Math
s = setnew(5:3, 1, 2)
s
abs(s)
cumsum(s)
round(s)
exp(s)
# Summary
range(s)
min(s)
max(s)
s1 = setnew(1, 1:2)
s2 = setnew(2, 1:2)
s1 + s2 # same as s1 | s2 or c(c1, s2)
s2 + s1 # same
s1 - s2
s2 - s1
s1 = setnew(1, b = 2)
s2 = setnew(1, b = 4)
s1 & s2 # {1}
s1 | s2 # {1, b = 2, b = 4}