I want to take a vector describing the location of a cell in an array, ie "x=c(row, column)
", and return the scalar index of that location. While this can be done with arithmetic, I'm trying to keep my code relatively easily to read. It seems weird to me that arrayInd
will turn your scalar index into a location vector, but I can't turn a location vector back into a scalar index.
Example code:
x <- array(seq(0.1,2.7,1), dim=c(3,3,3))
locVec <- c(3,1,1)
mysteryFunc(locVec)
which would return 3.
arrayInd(x[[mysteryFunc(locVec)]], .dim=dim(x))
returns locVec