Skip to content
Prev 237956 / 398500 Next

vectorizing: selecting one record per group

On Oct 13, 2010, at 4:17 PM, Erik Iverson wrote:

            
Perhaps using sampling to derive an index?

A[ tapply(1:100, A[,3], sample, 1), ]

 > A[tapply(1:100, A[,3], sample, 1), ]
            [,1]      [,2] [,3]
[1,] -1.9512142 0.9823905    1
[2,]  1.4983879 0.4961661    2
[3,]  0.7815468 0.3531835    3
[4,] -0.9210731 0.6508500    4
[5,]  0.2354838 0.8616220    5

--  
David.
David Winsemius, MD
West Hartford, CT