[R] counting the number of ones in a vector

sjaffe sjaffe at riskspan.com
Thu Mar 4 19:59:14 CET 2010

I got tired of writing length(which()) so I define a useful function which I
source in my .Rprofile:

count <- function( x ) length(which(x))


count( x == 1 )

View this message in context: http://n4.nabble.com/counting-the-number-of-ones-in-a-vector-tp1570700p1578549.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list