R Programming: Count the specific value in a given vector
R Programming: Vector Exercise-11 with Solution
Write a R program to count the specific value in a given vector.
Sample Solution :
R Programming Code :
x = c(10, 20, 30, 20, 20, 25, 9, 26)
print("Original Vectors:")
print(x)
print("Count specific value(20) in above vector:")
print(sum(x==20))
Sample Output:
[1] "Original Vectors:" [1] 10 20 30 20 20 25 9 26 [1] "Count specific value(20) in above vector:" [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 test whether a given vector contains a specified element.
Next: Write a R program to access the last value in a given 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