convertIndex {crochet} | R Documentation |
Convert Non-Numeric Index Types to Positive Integers
Description
Converts different index types such as negative integer vectors, character vectors, or logical vectors into positive integer vectors.
Usage
convertIndex(x, i, type, allowDoubles = FALSE)
Arguments
x |
A matrix-like object. |
i |
The index to convert: may be a one-dimensional or two-dimensional logical, character, integer, or double vector. |
type |
The type of index to convert to: |
allowDoubles |
If set, indices of type double are not converted to integers if the
operation would overflow to support matrices with |
Value
The converted index.
See Also
extract
and replace
to generate implementations
for [
and [<-
for custom types that use convertIndex
under the hood.
Examples
x <- matrix(data = rnorm(25), nrow = 5, ncol = 5)
dimnames(x) <- list(letters[1:5], letters[1:5])
convertIndex(x, c(1, 2, 3), "k")
convertIndex(x, -25, "k")
convertIndex(x, c(TRUE, FALSE), "k")
convertIndex(x, c(1, 2, 3), "i")
convertIndex(x, -5, "i")
convertIndex(x, c(TRUE, FALSE), "i")
convertIndex(x, c("a", "b", "c"), "i")
convertIndex(x, c(1, 2, 3), "j")
convertIndex(x, -5, "j")
convertIndex(x, c(TRUE, FALSE), "j")
convertIndex(x, c("a", "b", "c"), "j")