Here we are explaining how to write an R program to count the specific value in a given vector. Here we are using a built-in function sum() for this finding. The sum() function helps to returns the count of specific values in the vector. The syntax of sum is,
Below are the steps used in the R program to count the specific value in a given vector. In this R program, we directly give the values to built-in functions. And print the function result. Here we used variable A for assigning vector values.
A = c(20, 30, 30, 10, 30, 25, 30, 27)
print("Original Vectors:")
## [1] "Original Vectors:"
print(A)
## [1] 20 30 30 10 30 25 30 27
print("Count specific value(30) in above vector:")
## [1] "Count specific value(30) in above vector:"
print(sum(A==30))
## [1] 4
B = c(25, 35, 35, 15, 35, 25, 25, 57)
print("Original Vectors:")
## [1] "Original Vectors:"
print(A)
## [1] 20 30 30 10 30 25 30 27
print("Count specific value(25) in above vector:")
## [1] "Count specific value(25) in above vector:"
print(sum(A==25))
## [1] 1