# Re: [R] apply mean to a three-dimension data

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Thu, 24 Mar 2011 15:57:06 -0400

Sorry, the above should have been

> mymean <- function(x) Reduce("+", x)/length(x)
> mymean(b)

[,1] [,2]
[1,] 10.33333 12.33333
[2,] 11.33333 13.33333

Apologies for the noise.

Best,
Jorge

On Thu, Mar 24, 2011 at 3:54 PM, Jorge Ivan Velez <> wrote:

> Hi Hui,
>
> Ssee ?Reduce for more details. You might try something along the lines of
>
> > mymean <- function(x) Reduce("+", x)/length(x)
> [,1] [,2]
> [1,] 10.33333 12.33333
> [2,] 11.33333 13.33333
>
> HTH,
> Jorge
>
>
> On Thu, Mar 24, 2011 at 11:07 AM, Hui Du <> wrote:
>
>> Hi All,
>>
>> Suppose I have data like
>>
>> b[[1]] = matrix(1:4, 2, 2)
>> b[[2]] = matrix(10:13, 2, 2)
>> b[[3]] = matrix(20:23, 2, 2)
>>
>> [[1]]
>> [,1] [,2]
>> [1,] 1 3
>> [2,] 2 4
>>
>> [[2]]
>> [,1] [,2]
>> [1,] 10 12
>> [2,] 11 13
>>
>> [[3]]
>> [,1] [,2]
>> [1,] 20 22
>> [2,] 21 23
>>
>> Now I want to calculate the mean of each cell across the
>> list. For example mean of (b[[1]][1,1], b[[2]][1,1], b[[3]][1,1]), mean of
>> (b[[1]][1,2], b[[2]][1,2], b[[3]][1,2]) etc. e.g. mean of (1, 10, 20), mean
>> of(3, 12, 22). Could somebody tell me how to do it? Thank you in advance.
>>
>> HXD
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

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 Thu 24 Mar 2011 - 20:40:57 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 Thu 24 Mar 2011 - 20:50:24 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.