numeric not equal its value
Jannis,
Not strange. Try with numbers that can be exactly represented in binary
(that's what computers use), e.g.,
a<-seq(5,70,by=5)
b<-15
a==b
or fractions,
a<-seq(1/32,14/32,by=1/32)
b<-3/32
a==b
Most decimal fractions cannot be represented exactly although a bit of
magic will display them as if they are.
A little digging into the r-help archives will find further explanation.
Clint
Clint Bowman INTERNET: clint at ecy.wa.gov
Air Quality Modeler INTERNET: clint at math.utah.edu
Department of Ecology VOICE: (360) 407-6815
PO Box 47600 FAX: (360) 407-7534
Olympia, WA 98504-7600
USPS: PO Box 47600, Olympia, WA 98504-7600
Parcels: 300 Desmond Drive, Lacey, WA 98503-1274
On Mon, 20 May 2013, Jannis wrote:
Dear R users, I ran into the strange situation where a number does not seem to equal its value. Try this: a <- seq(0.05,0.7,0.05)[3] b <- 0.15 a == b Should this not be TRUE? a-b yields a very small number (and not 0) so this most probably is a numerical error, but why does seq create such numbers? Thanks a lot Jannis
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.