1

I'm getting a problem where I've got two vectors that should contain the same information, appear to contain the same information, but R seems to think that they're not identical.

I've reproduced this with a small test case:

> A <- c(3.7, 1.4, 2.3, 4.0, 0.0, 0.0)
> B <- c(3.9, 1.1, 2.1, 4.0, 0.0, 0.0)
> diff <- A - B
> C <- c(-0.2, 0.3, 0.2, 0.0, 0.0, 0.0)
> diff
[1] -0.2  0.3  0.2  0.0  0.0  0.0
> C
[1] -0.2  0.3  0.2  0.0  0.0  0.0
> identical(diff, C)
[1] FALSE
> which(diff != C)
[1] 1 2 3

The important thing is that diff appears to contain the same thing as C, but the identical function claims they don't, and the which function lists all non-zero values as being different.

Initially I thought that there was a round-off problem (i.e., diff[1] wasn't really -0.2, but -0.19999999 or something) but asking format to display more nsmall digits doesn't show anything else.

MikeTheTall
  • 3,214
  • 4
  • 31
  • 40

0 Answers0