[R] 3D array

Benilton Carvalho bcarvalh at jhsph.edu
Tue Dec 4 01:35:53 CET 2007


say your array is called "no.named.array".

then:

no.named.array[no.named.array == 0] <- NA
rowMeans(no.named.array, dims=2, na.rm=T)

b

On Dec 3, 2007, at 7:24 PM, threshold wrote:

>
> Hi, I deal with 3D array say:
>
> , , 1
>
>     [,1] [,2] [,3] [,4] [,5]
> [1,]    1    4    7   10   13
> [2,]    2    5    8   11   14
> [3,]    3    6    9   12   15
>
> , , 2
>
>     [,1] [,2] [,3] [,4] [,5]
> [1,]   16   19   22   25   28
> [2,]   17   20   23   26   29
> [3,]   18   21   24   27   30
>
> , , 3
>
>     [,1] [,2] [,3] [,4] [,5]
> [1,]   31   34   37   40   43
> [2,]   32   35   38   41   44
> [3,]   33   36   39   42   45
>
> I want to calculate means in the cells with respect to dimention 3rd  
> so for
> example (1+16+31)/3 or (15+30+45)/3  AND avoid taking zeros into  
> account.
>
> I did it with a loop but I guess there is the other more  
> straightforward
> method. will be very grateful for help...
>
> best, rob
> -- 
> View this message in context: http://www.nabble.com/3D-array-tf4940356.html#a14142187
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list