[R] count number of TRUEs in each row

Peter Langfelder peter.langfelder at gmail.com
Sun Apr 10 23:43:00 CEST 2011


On Sun, Apr 10, 2011 at 2:24 PM, Wendy <wendy2.qiao at gmail.com> wrote:
> Hi all,
>
> I have a huge matrix of TRUE/FALSE table like following, and I want to count
> the number of TRUEs in each row. Instead of looping through each row and do
> length(Z[Z==TRUE]), I am wondering if there is an easier way of doing this.
>
>       [,1]   [,2]    [,3]
> [1,]TRUE FALSE FALSE
> [2,]FALSE TRUE TRUE
>

rowSums(Z)

Peter



More information about the R-help mailing list