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?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics