To check if two lists are equal in R, you can use the identical
function or the all.equal
function.
In this example,
list1
and list2
with initial values.identical
function to check if list1
is identical to list2
.list1 <- c(1, 2, 3)
list2 <- c(1, 2, 3)
result <- identical(list1, list2)
print(result)
[1] TRUE
In this example,
list1
and list2
with initial values.all.equal
function to check if list1
is equal to list2
.list1 <- c(1, 2, 3)
list2 <- c(1, 2, 3)
result <- all.equal(list1, list2)
print(is.na(result))
[1] TRUE
In this tutorial, we learned How to check if Two Lists are Equal in R language with well detailed examples.