Can't tell exactly without seeing your data (try dput
), but this is mostly likely a consequence of FAQ 7.31.
(x1 <- 1)
## [1] 1
(x2 <- 1+1e-16)
## [1] 1
(x3 <- 1+1e-8)
## [1] 1
acos(x1)
## [1] 0
acos(x2)
## [1] 0
acos(x3)
## [1] NaN
That is, even if your values are so similar that their printed representations are the same, they may still differ: some will be within .Machine$double.eps
and others won't ...
One way to make sure the input values are bounded by [-1,1] is to use pmax
and pmin
: acos(pmin(pmax(x,-1.0),1.0))