Compare two Objects for Equality in R Programming – identical() Function
identical() function in R Language is used to return TRUE when two objects are equal else return FALSE.
Syntax: identical(a, b)
Parameters:
a, b: specified two objects
Example 1:
Python3
# R program to illustrate# identical function # Calling the identical() functionidentical(factorial(3), gamma(4))identical(lfactorial(5), log(factorial(5)))identical(exp(2) - 1, expm1(2)) |
Output:
[1] TRUE [1] TRUE [1] TRUE
Example 2:
Python3
# R program to illustrate# identical function # Calling the identical() functionidentical(.99, 1)identical(1, 1)identical(0, 0 / 2)identical(5, 25 / 5)identical(2, "2")identical(T, TRUE)identical(1, TRUE)identical(F, FALSE)identical(0, FALSE)identical(1 / 0, Inf)identical(0, -0)identical(NaN, -NaN) |
Output:
[1] FALSE [1] TRUE [1] TRUE [1] TRUE [1] FALSE [1] TRUE [1] FALSE [1] TRUE [1] FALSE [1] TRUE [1] TRUE [1] TRUE
Example 3:
Python3
# R program to illustrate# identical function # Elements are arranged sequentially by row.M <- matrix(c(3:14), nrow = 4, byrow = TRUE)print(M)# Elements are arranged sequentially by column.N <- matrix(c(3:14), nrow = 4, byrow = FALSE)print(N)# Calling identical() functionidentical(M, N) |
Output:
[, 1] [, 2] [, 3]
[1, ] 3 4 5
[2, ] 6 7 8
[3, ] 9 10 11
[4, ] 12 13 14
[, 1] [, 2] [, 3]
[1, ] 3 7 11
[2, ] 4 8 12
[3, ] 5 9 13
[4, ] 6 10 14
[1] FALSE


