Test How Many Elements Satify a Logical Condition in R (Example Code)

In this R tutorial you’ll learn how to return the number of elements that satisfy a condition.

Example: Applying the sum() Function to Get NUmber the of Elements that Satify a Logical Condition

sum(c(1, 3, 5, 3, 3, 7, 3) == 3)    # Counting TRUE values
# [1] 4

Further Resources & Related Articles

Have a look at the following R programming tutorials. They explain topics such as vectors, character strings, and variables.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top