Re: [R] 3D array

From: Ravi Varadhan <rvaradhan_at_jhmi.edu>
Date: Tue, 4 Dec 2007 09:40:04 -0500

The following will work:

apply(my.array, c(1,2), mean)

Ravi.



Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan_at_jhmi.edu

Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html  



-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of threshold
Sent: Monday, December 03, 2007 7:25 PM
To: r-help_at_r-project.org
Subject: [R] 3D array

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.

______________________________________________
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.
Received on Tue 04 Dec 2007 - 14:43:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 04 Dec 2007 - 15:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.