Count number of vector values in range with R
In this article, we will see how to count the number of vector values present in the given range in R. To achieve this functionality we can follow the following approach.
- Create vector
- Set range
- Iterate through the vector
- Check for elements that are within the range
- Add them
- Display sum
Implementation using this approach is given below.
 “Sum of elements in range : “
 “Sum of elements in specified range : “
However, if any of the elements of the vector is NA, then sum() method returns NA as the output. It can be ignored by specifying na.rm=TRUE.
 “Sum of elements in specified range without ignoring NA: “
 “Sum of elements in specified range ignoring NA: “