# R Check whether All Elements of Vector are the Same (Example Code)

In this tutorial you’ll learn how to evaluate if all vector elements are equal in R.

## Example Data

x <- rep(3, 10) # Example vector in R x # Display example vector in RStudio console # [1] 3 3 3 3 3 3 3 3 3 3 |

x <- rep(3, 10) # Example vector in R x # Display example vector in RStudio console # [1] 3 3 3 3 3 3 3 3 3 3

## Example: Checking for Equality of All Vector Elements Using var() Function

var(x) == 0 # Using var() function to test for equality # [1] TRUE |

var(x) == 0 # Using var() function to test for equality # [1] TRUE

## Further Resources & Related Articles

Please find some further R programming tutorials on topics such as loops and vectors below: