aperm方法
Transpose an array by permuting its dimensions and optionally resizing it.
aperm(a, perm, ...)
a
the array to be transposed.
perm
the subscript(下标) permutation vector, usually a permutation(组合) of the integers 1:n, where n is the number of dimensions of a. When a has named dimnames, it can be a character vector of length n giving a permutation of those names. The default (used whenever perm has zero length) is to reverse the order of the dimensions.
permutation
置换;排列(方式);组合(方式)
交换;变换;彻底改变
> x <- array(1:24, 2:4)
> x
, , 1
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
, , 2
[,1] [,2] [,3]
[1,] 7 9 11
[2,] 8 10 12
, , 3
[,1] [,2] [,3]
[1,] 13 15 17
[2,] 14 16 18
, , 4
[,1] [,2] [,3]
[1,] 19 21 23
[2,] 20 22 24
> xt <- aperm(x, c(2,1,3))
> xt
, , 1
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 5 6
, , 2
[,1] [,2]
[1,] 7 8
[2,] 9 10
[3,] 11 12
, , 3
[,1] [,2]
[1,] 13 14
[2,] 15 16
[3,] 17 18
, , 4
[,1] [,2]
[1,] 19 20
[2,] 21 22
[3,] 23 24
让我来解释下perm的意思吧
原来的数组的维度是行,列,层分别为2,3,4
现在perm=2,1,3
2的意思是原来下标是2的那个数(排在第二个的参数),现在排在第一位(行)
1的意思是原来下标是1的那个数,现在排在第2位(列)
3的意思是原来下标是3的那个数,现在排在第三位(层)
所以perm=2,1,3的等价于(3,2,4)