[R] arrayInd and which

R. Michael Weylandt michael.weylandt at gmail.com
Fri Apr 5 17:07:37 CEST 2013


On Fri, Apr 5, 2013 at 2:08 PM, Keith S Weintraub <kw1958 at gmail.com> wrote:
> And to the rest of you good R folks I would still be interested to see a working example of arrayInd, what it's supposed to do and what it's used for.

A little utility function for dealing with the
matrix-is-really-a-vector indexing duality. (Elemental (1,3) vs linear
#4 indexing)

E.g.,

x <- matrix(rnorm(9), 3, 3)

which.min(x) # Not super helpful

where.min <- function(x) arrayInd(which.min(x), dim(x), dimnames(x), T)

where.min(x) # Perhaps better

Cheers,
Michael



More information about the R-help mailing list