Skip to content
Prev 59634 / 398502 Next

number of pairwise present data in matrix with missings

Suppose your matrix is called A (`matrix' is not a good name). Then 
crossprod(!is.na(A)) is pretty efficient.  Test:
[,1] [,2] [,3]
[1,]   NA    1    1
[2,]    1   NA    1
[3,]   NA    1    1
[4,]    1    1    1
[5,]    1    1    1
[6,]    1    1    1
[,1] [,2] [,3]
[1,]    4    3    4
[2,]    3    5    5
[3,]    4    5    6
On Tue, 23 Nov 2004, Andreas Wolf wrote: