identical

identical(x, y)
Check whether x and y are identical objects.
  • x – Any R object.
  • y – Any R object.

Example. Below we show that we can recreate two identical sets of pseudorandom numbers — exactly — by setting the seed. We verify that the two sets are identical using the identical function.
> set.seed(5)
> x <- rnorm(3)
> x
[1] -0.8408555  1.3843593 -1.2554919
> set.seed(5)
> y <- rnorm(3)
> y
[1] -0.8408555  1.3843593 -1.2554919
> identical(x, y)
[1] TRUE
> z <- c(-0.8408555, 1.3843593, -1.2554919)
> identical(x, z)
[1] FALSE
The objects x and y are not just really similar; they are identical. If we investigated z, we would find that x and z are different due to rounding errors.
Tip. The identical function may be applied to complex R objects, including lists and functions.

Leave a Reply