To check if two vectors have the same items regardless of order in R, you can use the `identical()` function after sorting both vectors.
In this example,
vector1
and vector2
.sort()
function.identical()
function to check if the sorted vector1
is identical to the sorted vector2
.identical()
function returns TRUE
if the vectors have the same items regardless of order, otherwise FALSE
.vector1 <- c(3, 1, 2)
vector2 <- c(1, 2, 3)
identical(sort(vector1), sort(vector2))
[1] TRUE
In this example,
vector1
and vector2
.sort()
function.identical()
function to check if the sorted vector1
is identical to the sorted vector2
.identical()
function returns TRUE
if the vectors have the same items regardless of order, otherwise FALSE
.vector1 <- c('b', 'c', 'a')
vector2 <- c('a', 'b', 'c')
identical(sort(vector1), sort(vector2))
[1] TRUE
In this tutorial, we learned How to check if Two Vectors have Same Items (Regardless of Order) in R language with well detailed examples.