How to count TRUE values in a logical vector

后端 未结 8 1595
[愿得一人]
[愿得一人] 2020-11-28 01:17

In R, what is the most efficient/idiomatic way to count the number of TRUE values in a logical vector? I can think of two ways:

z <- sample(c         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 02:10

    Another option is to use summary function. It gives a summary of the Ts, Fs and NAs.

    > summary(hival)
       Mode   FALSE    TRUE    NA's 
    logical    4367      53    2076 
    > 
    

提交回复
热议问题