arrayIndex

0th

Percentile

Converts vector indices to array indices

Converts vector indices to array indices assuming last array dimension to "move fastest", e.g. matrices are stored column by column.

Keywords
manip, internal, utilities
Usage
# S3 method for default
arrayIndex(i, dim, ...)
Arguments
i

A vector of vector indices to be converted to array indices.

dim

A non-empty numeric vector specifying the dimension of the array.

...

Not used.

Value

Returns an integer matrix of length(i) rows and length(dim) columns.

References

[1] H. Bengtsson, Bayesian Networks - a self-contained introduction with implementation remarks, Master's Thesis in Computer Science, Mathematical Statistics, Lund Institute of Technology, 1999.

See Also

From R v2.11.0 there is arrayInd(), which does the same thing as this method. which() with argument arr.ind=TRUE.

Aliases
  • arrayIndex.default
  • arrayIndex
Examples
# NOT RUN {
# Single index
print(arrayIndex(21, dim=c(4,3,3)))

# Multiple indices
print(arrayIndex(20:23, dim=c(4,3,3)))

# Whole array
x <- array(1:30, dim=c(5,6))
print(arrayIndex(1:length(x), dim=dim(x)))

# Find (row,column) of maximum value
m <- diag(4-abs(-4:4))
print(arrayIndex(which.max(m), dim=dim(m)))

# }
Documentation reproduced from package R.utils, version 2.8.0, License: LGPL (>= 2.1)

Community examples

Looks like there are no examples yet.