setmatch: Set Operations

setmatchR Documentation

Set Operations

Description

Series of functions extending existing vector operations to lists of vectors.

Usage

setmatch(x, y, nomatch = NA_integer_)

setsetequal(x, y)

setsetdiff(x, y)

subsetmatch(x, y, nomatch = NA_integer_)

supersetmatch(x, y, nomatch = NA_integer_)

Arguments

x

list of vectors.

y

list of vectors.

nomatch

value to be returned in the case when no match is found. Note that it is coerced to integer.

Details

setmatch checks whether each vector in the list x is also contained in the list y, and if so returns position of the first such vector in y. The ordering of the elements of the vector is irrelevant, as they are considered to be sets.

subsetmatch is similar to setmatch, except vectors in x are searched to see if they are subsets of vectors in y. Similarly supersetmatch consideres if vectors in x are supersets of vectors in y.

setsetdiff is a setwise version of setdiff, and setsetequal a setwise version of setequal.

Value

setmatch and subsetmatch return a vector of integers of length the same as the list x.

setsetdiff returns a sublist x.

setsetequal returns a logical of length 1.

Functions

  • setsetequal: Test for equality of sets

  • setsetdiff: Setdiff for lists

  • subsetmatch: Test for subsets

  • supersetmatch: Test for supersets

Note

These functions are not recursive, in the sense that they cannot be used to test lists of lists. They also do not reduce to the vector case.

Author(s)

Robin Evans

See Also

match, setequal, setdiff

Examples


x = list(1:2, 1:3)
y = list(1:4, 1:3)
setmatch(x, y)
subsetmatch(x, y)
setsetdiff(x, y)

x = list(1:3, 1:2)
y = list(2:1, c(2,1,3))
setsetequal(x, y)


rje documentation built on Nov. 12, 2022, 9:06 a.m.