Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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?