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