Learn R Programming

rje (version 1.4)

arrayInd: Faster calculation of array indices from vector position.

Description

Calculates array indices based on linear position in an array.

Usage

arrayInd(ind, .dim, .dimnames = NULL, useNames = FALSE)

Arguments

ind
integer-valued vector of indices.
.dim
integer vector givine dimensions of array.
.dimnames
optional list of character dimnames(.), of which only .dimnames[[1]] is used.
useNames
logical indicating if the value of arrayInd() should have (non-null) dimnames at all.

Value

  • A matrix whose rows each are the indices of one element of x; see Examples below.

Details

This is a C implementation of the base function of the same name. Results should be the same.

Given a vector of integers giving the vector position of entries in an array, returns the appropriate array indices.

See Also

arrayInd.

Examples

Run this code
arr = array(1:36, dim=c(2,3,2,3))
ind = arrayInd(c(4,9,17), c(2,3,2,3))
ind

arr[2,2,1,1]
arr[1,2,2,1]
arr[1,3,1,2]

Run the code above in your browser using DataLab