Re: [R] summary statistics for lists of matrices or dataframes

From: Patrick Burns <pburns_at_pburns.seanet.com>
Date: Wed 11 May 2005 - 00:56:27 EST

No, you can't. Because 'bind.array' doesn't take an arbitrary number of arguments. Robert's solution does what I had in mind.

Patrick Burns wrote:

> You could use 'do.call' with 'bind.array' (from S Poetry) or 'abind'
> to convert your list of matrices into a three-dimensional array.
>
> Patrick Burns
>
> Burns Statistics
> patrick@burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S User")
>
> David Kane wrote:
>
>> Is there a simple way to calculate summary statistics for all the
>> matrices or dataframes in a list? For example:
>>
>>
>>
>>> z <- list(matrix(c(2,2,2,2), ncol = 2), matrix(c(4,4,4,4), ncol = 2))
>>> z
>>>
>>
>> [[1]]
>> [,1] [,2]
>> [1,] 2 2
>> [2,] 2 2
>>
>> [[2]]
>> [,1] [,2]
>> [1,] 4 4
>> [2,] 4 4
>>
>>
>>
>> I would like to calculate, for example, the mean value for each
>> cell. I can do that the hard way as:
>>
>>
>>
>>> (z[[1]] + z[[2]]) / 2
>>>
>>
>> [,1] [,2]
>> [1,] 3 3
>> [2,] 3 3
>>
>>
>>
>> But there must be an easier way. I am also interested in other
>> statistics (like median and sd). Since all my matrices have the same
>> attributes (especially row and column names), I would like to preserve
>> those in the answer.
>>
>> Thanks,
>>
>> Dave Kane
>>
>> In case it matters:
>>
>>
>>
>>> R.version
>>>
>>
>> _ platform i686-pc-linux-gnu
>> arch i686 os linux-gnu system i686,
>> linux-gnu status major 2
>> minor 1.0 year 2005 month
>> 04 day 18 language R
>>
>>
>> ______________________________________________
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>>
>>
>>
>>
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed May 11 01:01:49 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:40 EST