# interchange the first two subscripts on a 3-way array x
x <- array(1:24, 2:4)
xt <- aperm(x, c(2,1,3))
stopifnot(t(xt[,,2]) == x[,,2],
t(xt[,,3]) == x[,,3],
t(xt[,,4]) == x[,,4])
# table objects
str(UCBAdmissions)
UCB <- aperm(UCBAdmissions, c(2, 1, 3))
str(UCB)
Run the code above in your browser using DataLab