R Programming: Count number of values in a range in a given vector
R Programming: Vector Exercise-22 with Solution
Write a R program to count number of values in a range in a given vector.
Sample Solution :
R Programming Code :
v = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90)
print("Original vector:")
print(v)
ctr = sum(v > 10 & v < 50)
print("Number of vector values between 10 and 50:")
print(ctr)
Sample Output:
[1] "Original vector:" [1] 0 10 20 30 40 50 60 70 80 90 [1] "Number of vector values between 10 and 50:" [1] 3
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to concatenate a vector.
Next: Write a R program to convert two columns of a data frame to a named vector.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework