linearInd {DelayedArray} | R Documentation |
linearInd
performs the reverse conversion of
base::arrayInd
, that is, it converts so-called
array indices (i.e. n-uplets) into linear indices.
linearInd(aind, dim)
aind |
Typically a numeric matrix like one returned by
For convenience, Note that no bounds checking is performed, that is, values in the j-th
column of |
dim |
An integer vector containing the dimensions of the underlying array. Note that |
An integer vector with one element per row in aind
if
aind
is a matrix.
A single integer if aind
is a vector.
arrayInd
in the base package for the reverse
conversion.
dim <- 4:2 linearInd(c(4, 3, 1), dim) linearInd(c(4, 3, 2), dim) aind <- rbind(c(1, 1, 1), c(2, 1, 1), c(3, 1, 1), c(4, 1, 1), c(1, 2, 1), c(1, 1, 2), c(4, 3, 2)) linearInd(aind, dim) ## With a matrix of dimensions: dims <- rbind(c(4L, 3L), c(5L, 3L), c(6L, 3L)) aind <- rbind(c(1, 2), c(1, 2), c(1, 2)) linearInd(aind, dims) ## Sanity checks: dim <- c(33:30, 45L, 30L) stopifnot(linearInd(rep(1, 6), dim) == 1) stopifnot(linearInd(dim, dim) == prod(dim)) stopifnot(identical(linearInd(arrayInd(1:120, 6:4), 6:4), 1:120)) stopifnot(identical(linearInd(arrayInd(840:1, 4:7), 4:7), 840:1))