[R] how to ave this?

Mike Meredith mmeredith at wcs.org
Sat Jun 23 09:40:58 CEST 2007



The simplest solution in this case would be:

(x[[1]] + x[[2]])/2

But that approach would get messy with >2 matrices in your list. Maybe
change your list to an array, then use 'apply':

n <- length(x)
y <- array(unlist(x), c(3,2,n))
apply(y, 1:2, mean)

HTH, Mike


Weiwei Shi wrote:
> 
> one of my approaches is:
> 
> x0 = sapply(mylist, cbind)
> 
> and manipulate from x0 (x0[1:nrow(x0)/2, ] correponds to fc and the
> lower part is tt.
> 
> but it is not neat way.
> 
> 
> On 6/22/07, Weiwei Shi <helprhelp at gmail.com> wrote:
>> Hi,
>>
>> I have a list that looks like this:
>> [[1]]
>>              fc          tt
>> 50   0.07526882 0.000000000
>> 100  0.09289617 0.000000000
>> 150  0.12359551 0.000000000
>>
>> [[2]]
>>              fc          tt
>> 50   0.02040816 0.000000000
>> 100  0.03626943 0.005025126
>> 150  0.05263158 0.010101010
>>
>> and I am wondering how to "average" it so that I have one matrix t0 at
>> the end, and t0[1,1] = (0.075..+0.0204..)/2
>>
>> Thanks,
>>
>> --
>> Weiwei Shi, Ph.D
>> Research Scientist
>> GeneGO, Inc.
>>
>> "Did you always know?"
>> "No, I did not. But I believed..."
>> ---Matrix III
>>
> 
> 
> -- 
> Weiwei Shi, Ph.D
> Research Scientist
> GeneGO, Inc.
> 
> "Did you always know?"
> "No, I did not. But I believed..."
> ---Matrix III
> 
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-ave-this--tf3965210.html#a11264004
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list