arrays - removing axis headers from aaply results -


i'm using aaply (of plyr package) provide simple summary stats on n-space array. source array has axis headers not row/column names. simplified example:

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

note have axis names no row/column names. when want summarize along axis, header names added:

(mtx2 <- aaply(mtx, c(3,2), sum)) ##    b ## c    1  2  3  4 ##   1  6 15 24 33 ##   2 42 51 60 69 

note have row/column names (strings) of '1', '2', etc. can manually remove them with:

dimnames(mtx2) <- list(c=null, b=null) 

or more generically with:

dimnames(mtx2) <- structure(replicate(length(dim(mtx2)), null), .names=names(dimnames(mtx2))) 

but prefer not include row/column headers in first place.

is there option i'm missing (to aaply) this?

(btw: know it's cosmetic, , can still reference rows/columns/etc using integer indices. point aesthetic focused on providing consistent output function calls.)

edit: i'm using other options aaply() provides apply() not, hoping consistent function calls.

so clear, using aaply(...) in plyr package, , adding row , column names:

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" 

you can achieve same result in base r using apply(...), without getting column or row names:

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 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -