Skip to content
Related Articles

Related Articles

all.equal() Function in R

Improve Article
Save Article
  • Last Updated : 02 Jun, 2022
Improve Article
Save Article

all.equal() Function in R Programming Language is used to test whether the given vectors are nearly equal or not.

Syntax:

all.equal(vector1,vector2) 

where, vector1 is the first input vector and vector2 is the second input vector.

Note:If the vectors are equal  it will return TRUE, if they are nearly equal it will return the Mean relative difference.

Example 1:

In this example, we are creating 2 equal vectors with 5 elements each and applying all.equal() and will be getting true value in the R programming language.

R




# create first vector
vector1 = c(2, 3, 4, 5, 6)
  
# create second vector
vector2 = c(2, 3, 4, 5, 6)
  
# check both are equal or not.
print(all.equal(vector1, vector2))


Output:

[1] TRUE

Example 2:

In this example, we are creating 2 unequal vectors with 5 elements each and apply all.equal() and getting the mean relative difference accordingly in the R programming language.

R




# create first vector
vector1 = c(2, 3, 4, 5, 6)
  
# create second vector
vector2 = c(2.4, 3.1, 4.6, 5.33, 6.33)
  
# check both are equal or not.
print(all.equal(vector1, vector2))


Output:

[1] "Mean relative difference: 0.088"
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!