 # R Program to count the specific value in a given vector

## How to count the specific value in a given vector

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,

``````sum(x, na.rm = FALSE, …) #Where x is a vector
```
```

## How to count the specific value in a given vector in the R program

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.

## ALGORITHM

STEP 1: Assign variable A with vector values

STEP 2: First print original vector values

STEP 3: Call the function sum of finding element count as sum(A==30)

STEP 4: print the result of the function

## R Source Code

```                                          ```A = c(20, 30, 30, 10, 30, 25, 30, 27)
print("Original Vectors:")
print(A)
print("Count specific value(30) in above vector:")
print(sum(A==30))
```
```

## OUTPUT

``` "Original Vectors:"
 20, 30, 30, 10, 30, 25, 30, 27
 "Count specific value(30) in above vector:"
 4
```
VIEW ALL
VIEW ALL
VIEW ALL