[R] mode across lists of matrices
Gregory Ryslik
rsaber at comcast.net
Tue Sep 21 15:47:05 CEST 2010
Hi Everyone,
I am interested in taking the mode over several thousand matrices. I show an example below. For the [1,1] entry of my "mode" matrix that I want to create I would like to have a "2". For the [1,2] entry I would want a 2. For the [2,2] entry it would be 4 and so forth. Earlier, I was working with continuous cases and thus each (n,m) element was simply an average. I was able to then do element-wise addition and counting using the "Reduce" function and then the average would be totalsum/totalcount where the NA terms were discounted. Here, it's not exactly a binary case so Reduce doesn't quite work as well. I'm open to suggestions but would as always like to avoid long loops as that will significantly bump up running time over several thousand trees. Similarly, I would not like to do a lot of sorts to find the mode either...
Thanks for your help!
mymats
[[1]]
[,1] [,2] [,3]
[1,] 0 2 1
[2,] 2 3 3
[3,] 2 1 2
[[2]]
[,1] [,2] [,3]
[1,] 1 2 4
[2,] 2 4 4
[3,] 3 4 5
[[3]]
[,1] [,2] [,3]
[1,] 2 3 1
[2,] 3 4 2
[3,] 5 1 3
[[4]]
[,1] [,2] [,3]
[1,] 2 4 2
[2,] 1 NA 2
[3,] 2 3 1
[[5]]
[,1] [,2] [,3]
[1,] NA 2 1
[2,] 2 4 1
[3,] 1 3 2
More information about the R-help
mailing list