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

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

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:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top