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

sum(vector)

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
Status <- c(TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,TRUE,FALSE)

# Count TRUE value 
s <- sum(Status)

# Print count
print(s)

Output:

[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.