문제

In R, why is this false for y > 2?

y <- c(1, 2, 3, 4, 5)
x <- 2*y
exp(log(x)) == exp(log(y)) * 2
[1]  TRUE  TRUE FALSE FALSE FALSE
도움이 되었습니까?

해결책

Numeric precision. Try calculating the difference:

exp(log(x)) - exp(log(y)) * 2

You could use something like:

all.equal( exp(log(x)) , exp(log(y)) * 2 )

다른 팁

Exactly, the numerci precision is the cause. Try this, even simpler calculation

1/2+1/3+1/6 #equal to 1    
(1/2+1/3+1/6)-1 # should be 0
[1] -1.110223e-16
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top