| List-comparison {S4Vectors} | R Documentation |
Compare and order list-like objects
Description
Methods for comparing and ordering List objects and ordinary lists by recursing into their elements.
Usage
## Element-wise (aka "parallel") comparison of list-like objects
## -------------------------------------------------------------
## S4 method for signature 'list,List'
pcompare(x, y)
## S4 method for signature 'List,list'
pcompare(x, y)
## S4 method for signature 'List,List'
pcompare(x, y)
## S4 method for signature 'list,List'
e1 == e2
## S4 method for signature 'List,list'
e1 == e2
## S4 method for signature 'List,List'
e1 == e2
## S4 method for signature 'list,List'
e1 <= e2
## S4 method for signature 'List,list'
e1 <= e2
## S4 method for signature 'List,List'
e1 <= e2
## match(), duplicated(), and unique()
## -----------------------------------
## S4 method for signature 'list,List'
match(x, table, nomatch = NA_integer_,
incomparables = NULL, ...)
## S4 method for signature 'List,list'
match(x, table, nomatch = NA_integer_,
incomparables = NULL, ...)
## S4 method for signature 'List,List'
match(x, table, nomatch = NA_integer_,
incomparables = NULL, ...)
## S4 method for signature 'List,vector'
match(x, table, nomatch = NA_integer_,
incomparables = NULL, ...)
## S4 method for signature 'List,Vector'
match(x, table, nomatch = NA_integer_,
incomparables = NULL, ...)
## S4 method for signature 'List'
duplicated(x, incomparables=FALSE, fromLast=FALSE, ...)
## S4 method for signature 'List'
unique(x, incomparables=FALSE, ...)
## order() and related methods
## ---------------------------
## S4 method for signature 'List'
order(..., na.last = TRUE, decreasing = FALSE,
method = c("auto", "shell", "radix"))
## S4 method for signature 'List'
sort(x, decreasing=FALSE, na.last=NA, by)
## S4 method for signature 'List'
rank(x, na.last = TRUE,
ties.method = c("average", "first", "random", "max", "min"))
## S4 method for signature 'List'
is.unsorted(x, na.rm = FALSE, strictly = FALSE)
## Low-level helper for recursive comparison
## -----------------------------------------
pcompareRecursively(x)
Arguments
x, y, e1, e2, table |
List-like objects. |
nomatch |
See |
incomparables |
See |
fromLast |
See |
ties.method |
See |
na.rm, strictly |
See |
method |
See |
decreasing, na.last |
See |
by |
Not supported for recursively compared list-like objects. |
... |
Extra arguments supported by specific methods and propagated to the underlying element-wise operations. |
Details
Ordinary List objects and ordinary lists compare
recursively by default. That is, pcompare(), the binary comparison
operators, and related helpers are applied element-wise to the list
elements, and typically return list-like results parallel to the inputs
rather than a flat integer or logical vector.
Whether a list-like object should compare recursively is controlled by the
low-level pcompareRecursively() generic. The default methods return
TRUE for List objects and ordinary lists. Specific subclasses
can override this and return FALSE when they should be compared as
atomic vector-like entities rather than by recursing into their elements.
The recursive methods are implemented by applying the corresponding scalar
or vector operation to each list element. For example, match() and
duplicated() return list-like objects parallel to x, and
order() returns an IntegerList containing the order
within each list element. Similarly, is.unsorted() is applied to
each list element and returns one logical value per element of x.
Value
For pcompare: typically an IntegerList parallel to
the longer input.
For pcompareRecursively: a single logical indicating whether
comparisons on x should recurse into its elements.
For match: typically an IntegerList parallel to
x.
For duplicated: typically an LogicalList parallel to
x.
For unique: an object like x, with duplicates removed within
each list element when recursive comparison is used.
For order: an IntegerList parallel to the input.
For sort: an object like x, with each list element sorted.
For rank: an IntegerList parallel to the input.
For is.unsorted: a logical vector of length length(x),
indicating for each list element whether that element is unsorted.
See Also
The List class.
-
Vector-comparison for the corresponding methods on vector-like objects.
-
IPosRanges-comparison in the IRanges package for comparing and ordering ranges.
Examples
x <- splitAsList(6:1, c(1, 1, 2, 2, 3, 3))
y <- splitAsList(c(6, 1, 4, 3, 1, 2), c(1, 1, 2, 2, 3, 3))
pcompare(x, y)
duplicated(x)
sort(x)