[R] Counting in Matrix

Erik Iverson eiverson at NMDP.ORG
Tue Dec 15 23:00:05 CET 2009


?rowSums

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Tom Pitt
> Sent: Tuesday, December 15, 2009 2:57 PM
> To: r-help at r-project.org
> Subject: [R] Counting in Matrix
> 
> 
> Hi All,
> 
> Is there an easy way to count "TRUEs" for each row?
> 
> Thanks,
> Tom
> 
> 
>       x1    x2    x3    x4
> 1   TRUE  TRUE  TRUE  TRUE
> 2  FALSE  TRUE  TRUE  TRUE
> 3   TRUE FALSE  TRUE  TRUE
> 4  FALSE FALSE  TRUE  TRUE
> 5   TRUE  TRUE FALSE  TRUE
> 6  FALSE  TRUE FALSE  TRUE
> 7   TRUE FALSE FALSE  TRUE
> 8  FALSE FALSE FALSE  TRUE
> 9   TRUE  TRUE  TRUE FALSE
> 10 FALSE  TRUE  TRUE FALSE
> 11  TRUE FALSE  TRUE FALSE
> 12 FALSE FALSE  TRUE FALSE
> 13  TRUE  TRUE FALSE FALSE
> 14 FALSE  TRUE FALSE FALSE
> 15  TRUE FALSE FALSE FALSE
> --
> View this message in context: http://n4.nabble.com/Counting-in-Matrix-
> tp964644p964644.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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