Re: [R] vectorizaton

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Wed 13 Jul 2005 - 00:38:02 EST


Try:

mymat <- rowMeans(P, dims=2)

Andy

> From: Dimitri Joe
>
> Hi,
>
> I got 1000 NxN matrices grouped in one array. I want one
> matrix in which p_ij is the average of all the 1000 matrices
> in the array. Here's what I'm trying to do:
>
> # P is the NxNx1000 array
>
> for(i in 1:N)
> for(j in 1:N)
> for(k in 1: 1000)
> mymat[ i, j ] <- mean( P [i , j , k ] )
>
> Otherwise, I could have a NxNx1000 vector, and get the N^2
> means of the 1+ (N^2)*(0: 999) elements. I don't know which
> is more efficient, but I wouldn't know how to carry this last
> solution out anyway. Any ideas on how to do this efficiently?
>
> Thanks,
>
> Dimitri
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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 Jul 13 00:43:16 2005

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