[R] matrices call a function element-wise

Jonathan Christensen dzhonatan at gmail.com
Tue Jan 4 03:27:12 CET 2011


Hi,

I would recommend reformatting the data as a 2x2x1000 array and using apply.

Jonathan


On Mon, Jan 3, 2011 at 7:57 AM, zhaoxing731 <zhaoxing731 at yahoo.com.cn> wrote:
> Hello
>
> I have 4 1000*1000 matrix A,B,C,D. I want to use the corresponding element of the 4 matrices. Using the "for loop" as follow:
>
> E<-o
> for (i in 1:1000)
>    {for (j in 1:1000)
>  {
>         E<-fisher.test(matrix(c(A[i][j],B[i][j],C[i][j],D[i][j]),2))#call fisher.test for every element
>  }
>    }
>
> It is so time-consuming
> Need vectorization
>
> Yours sincerely
>
>
>
>
> ZhaoXing
> Department of Health Statistics
> West China School of Public Health
> Sichuan University
> No.17 Section 3, South Renmin Road
> Chengdu, Sichuan 610041
> P.R.China
>
>        [[alternative HTML version deleted]]
>
>
> __________________________________________________
> 8O?lW"2aQE;"3,4sH]A?Cb7QSJOd?
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list