To check if two vectors are equal in R, you can use the `identical()` function or the `all.equal()` function.
In this example,
vector1
and vector2
.identical()
function to check if vector1
is identical to vector2
.identical()
function returns TRUE
if the vectors are identical, otherwise FALSE
.vector1 <- c(1, 2, 3)
vector2 <- c(1, 2, 3)
identical(vector1, vector2)
[1] TRUE
In this example,
vector1
and vector2
.all.equal()
function to check if vector1
is equal to vector2
.all.equal()
function returns TRUE
if the vectors are equal, otherwise FALSE
. It also handles numerical tolerance for numeric vectors.vector1 <- c('a', 'b', 'c')
vector2 <- c('a', 'b', 'c')
all.equal(vector1, vector2)
[1] TRUE
In this tutorial, we learned How to check if Two Vectors are Equal in R language with well detailed examples.