What is the identical() function in R?
Overview
The identical() function in R is used to test if two given R objects are exactly equal.
Syntax
identical(a, b)
Parameters
The identical() function takes the parameter values a and b that represent the R objects to be compared.
Note: The
identical()function can take two or more objects.
Return value
The identical() function returns either a TRUE or FALSE.
Example
# creating different R objects to be compareda <- c('Bar', 'Baz', 'Foo' );b <- c('Baz', 'Foo', 'Bar' );c <- c('Bar', 'Baz', 'Foo' );d <- c('Bar', 'Baz', 'Foo', 'Foo', 'Foo');# checking if a and b are equalidentical(a, b)# checking if a and c are equalidentical(a, c)# checking if a, and d are equalidentical(a, d)
Explanation
- Lines 2–5: We create R objects
a,b,canddfor comparison. - Line 8: We check if the objects
aandbare equal using theidentical()function. - Line 11: We check if the objects
aandcare equal using theidentical()function. - Line 14: We check if the objects
aanddare equal using theidentical()function.