![]() |
VOOZH | about |
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.
Approach
Implementation using this approach is given below.
Example 1:
Output
[1] "Sum of elements in range : "
[1] 3
Example 2:
Output
[1] "Sum of elements in specified range : "
[1] 4
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.
Example 3:
Output
[1] "Sum of elements in specified range without ignoring NA: "
[1] NA
[1] "Sum of elements in specified range ignoring NA: "
[1] 3