To count TRUE values in logical vector in R, you can use sum() function.

The following method shows how you can do it with syntax.

Method: Use sum() Function


The following example shows how to count TRUE valeus from logical vector in R.

Using sum() Function

Let’s see how we can use sum() function to count TRUE values in logical vector:

# Define vector

# Count TRUE value 
s <- sum(Status)

# Print count


[1] 4

Here the output shows count of TRUE values from logical vector. While using sum() function it takes TRUE as 1 and FALSE as 0.