comparisons: Compare IndexedRelations objects.

Description Element-wise comparisons Matching Ordering Author(s) See Also Examples

Description

Perform comparisons within or between IndexedRelations objects. This behaves “as if” the partnering features were directly represented in the object, i.e., comparisons are based on the features, not on the values of the integer indices. This is an important distinction if different objects have different feature sets, and/or if the feature sets contain duplicated entries.

Element-wise comparisons

pcompare(x, y) for two IndexedRelations x and y will return an integer vector of length equal to the longer of x and y. This contains negative, zero or positive values if the entry in x is “less than”, equal to or “greater than” the corresponding entry of y, respectively. Entries from the shorter object are recycled to reach the length of the longer object; unless one is of zero length, in which case an empty integer vector is returned.

The definitions of “less than”, etc., for relationships are based on comparisons between the partners involved. The first partner from each relationship are compared; if those are equal, the second partners are compared; and so on. If all partners are equal, the relationships are equal. Comparisons between partners are performed based on the definitions of (in)equality for that partner's feature class.

Matching

match(x, table, nomatch = NA_integer_, incomparables = NULL, ...) takes two IndexedRelations objects x and table. It returns an integer vector of length equal to x, specifying the first entry of table that is equal to each element of x. Elements of x without a match are assigned values of nomatch. All other arguments are ignored.

selfmatch(x, ...) takes an IndexedRelations object x and returns an integer vector specifying the first entry of x that is equal to each entry of x. This represents a more efficient specialization of match when table is directly equal to x. All other arguments are ignored.

In both cases, equality is based on the features rather than the indices of x and table.

Ordering

order(..., na.last=TRUE, decreasing=FALSE, method=c("auto", "shell", "radix")) will take any number of IndexedRelations objects of the same length in ..., and return an integer vector specifying the permutation required to order the first object. (For entries of the first object that are equal, the permutation will order them based on the second object, and so on.)

Ordering within each IndexedRelations object is performed based on the first partner, then on the second partner for entries that have the same first partner, and so on. Ordering of partners is based on the definition of sorting for that partner's feature class.

Author(s)

Aaron Lun

See Also

pcompare, to see the specification for Vector classes.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(IRanges)
r1 <- IRanges(1:10, width=1)
r2 <- IRanges(1:5, width=2)
i1 <- sample(length(r1), 20, replace=TRUE) 
i2 <- sample(length(r2), 20, replace=TRUE) 

IR <- IndexedRelations(list(i1, i2), list(r1, r2))
IR2 <- IndexedRelations(list(rev(i1), rev(i2)), list(r1, r2))

IR < IR2
IR > IR2
IR == IR2

match(IR, IR2)
IR[1:10] %in% IR # based on 'match'

selfmatch(IR)
duplicated(IR) # based on 'selfmatch'
unique(IR) # based on 'duplicated'

order(IR)
sort(IR) # based on 'order'

LTLA/IndexedRelations documentation built on June 2, 2019, 10:03 p.m.