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 Set.

.ordered

logical if TRUE all elements in the Set will be ordered.

x

R object of ANY type for as.set() and is.set() or of class Set for the S3 methods.

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().

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}


[Package container version 1.0.4 Index]