Imagine I have a simple 4x3x2 array in R.
> x <- array(1:24,c(4,3,2), dimnames=list(c('a','b','c','d'),c('x','y','z'),1:2))
> x
, , 1
x y z
a 1 5 9
b 2 6 10
c 3 7 11
d 4 8 12
, , 2
x y z
a 13 17 21
b 14 18 22
c 15 19 23
d 16 20 24
What I'd like, is a simple function on the array that gives me back the name of the index of each element for an arbitrary dimension. In this case, dimension 2.
The function would behave like this:
> arraydims(x,2) #Where 2 is dimension I want names for.
, , 1
[,1] [,2] [,3]
[1,] "x" "y" "z"
[2,] "x" "y" "z"
[3,] "x" "y" "z"
[4,] "x" "y" "z"
, , 2
[,1] [,2] [,3]
[1,] "x" "y" "z"
[2,] "x" "y" "z"
[3,] "x" "y" "z"
[4,] "x" "y" "z"