Get Number of Cases in Particular Range in R (Example Code)
In this R tutorial you’ll learn how to get the number of observations within a certain range of values.
Example Data
my_values <- 1:10 # Example vector in R my_values # Show example vector in RStudio console # [1] 1 2 3 4 5 6 7 8 9 10 |
my_values <- 1:10 # Example vector in R my_values # Show example vector in RStudio console # [1] 1 2 3 4 5 6 7 8 9 10
Example: Counting Number of Cases Larger Than X & Smaller Than Y
sum(my_values >= 5 & my_values <= 8) # Count cases in range # [1] 4 |
sum(my_values >= 5 & my_values <= 8) # Count cases in range # [1] 4
Further Resources & Related Articles
Have a look at the following R programming tutorials. They explain topics such as dplyr, counting, extracting data, and numeric values.