Arrays 从aaply结果中删除轴标头

Arrays 从aaply结果中删除轴标头,arrays,r,header,Arrays,R,Header,我正在使用aaply(属于plyr包)提供一个n空间数组的简单摘要统计数据。源数组具有轴标题,但没有行/列名。一个简化的例子: mtx <- array(1:24, dim=c(3,4,2)) dimnames(mtx) <- list(A=NULL, B=NULL, C=NULL) mtx ## , , 1 ## ## B ## A [,1] [,2] [,3] [,4] ## [1,] 1 4 7 10 ## [2,]

我正在使用
aaply
(属于
plyr
包)提供一个n空间数组的简单摘要统计数据。源数组具有轴标题,但没有行/列名。一个简化的例子:

mtx <- array(1:24, dim=c(3,4,2))
dimnames(mtx) <- list(A=NULL, B=NULL, C=NULL)
mtx
## , , 1
## 
##       B
## A      [,1] [,2] [,3] [,4]
##   [1,]    1    4    7   10
##   [2,]    2    5    8   11
##   [3,]    3    6    9   12
## 
## , , 2
## 
##       B
## A      [,1] [,2] [,3] [,4]
##   [1,]   13   16   19   22
##   [2,]   14   17   20   23
##   [3,]   15   18   21   24

mtx因此,为了清楚起见,您正在
plyr
包中使用
aaply(…)
,它正在添加行和列名:

library(plyr)
mtx2 <- aaply(mtx, c(3,2), sum)
str(mtx2)
#  int [1:2, 1:4] 6 42 15 51 24 60 33 69
#  - attr(*, "dimnames")=List of 2
#   ..$ C: chr [1:2] "1" "2"
#   ..$ B: chr [1:4] "1" "2" "3" "4"

的确如此。我一直在玩
plyr
系列的其他几个选项,这些选项在
apply()
中是不可用的,所以我希望在
aaply
中找到等价物,因为我可以在
apply
中找到。谢谢你的回复!(我将把这一点添加到原始问题中。)
dimnames(mtx2) <- list(C=NULL, B=NULL)
dimnames(mtx2) <- structure(replicate(length(dim(mtx2)), NULL), .Names=names(dimnames(mtx2)))
library(plyr)
mtx2 <- aaply(mtx, c(3,2), sum)
str(mtx2)
#  int [1:2, 1:4] 6 42 15 51 24 60 33 69
#  - attr(*, "dimnames")=List of 2
#   ..$ C: chr [1:2] "1" "2"
#   ..$ B: chr [1:4] "1" "2" "3" "4"
mtx3 <- apply(mtx, c(3,2), sum)
all(mtx2 == mtx3)
# [1] TRUE
str(mtx3)
#  int [1:2, 1:4] 6 42 15 51 24 60 33 69
#  - attr(*, "dimnames")=List of 2
#   ..$ C: NULL
#   ..$ B: NULL