[Rd] seq() does not create proper numbers (PR#10489)

rihle at gwdg.de rihle at gwdg.de
Tue Dec 4 13:10:12 CET 2007


Full_Name: Rico Ihle
Version: 2.6.1
OS: Windows XP Professional Version 2002 Pentium(R) 4 CPU 3.2 GHz
Submission from: (NULL) (134.76.183.24)


# Bug in seq() function:
x <- seq(-2,2,by=0.01)
which(x==0.05)# How that??
# although:
x# 0.05 seems to be at position 206 of x!!:
x[206]
# Why is this not equal to 0.05?

# Reason:
x2 <- as.character(x);x2
x2[206]# Ooooh... It's really not equal to 0.05!! How that? (compare lines 5 and
6!)

# Remedy:
x3 <- round(as.numeric(x),2)
which(x3==0.05)

# The (necessary) rounding is apparently and unfortunately NOT included in the
seq() function!!!
# But it should be!!!
# Because if one doesn't know about the demonstrated "nice" feature of the seq()
function
# (and it is not visible in lines 5 or 6!!!)
# one gets mad that x[206] is not equal to 0.05 although x[206] is printed as
0.05!!!

# Similarly:
y <-  seq(-0.5,.5,by=0.01)
which(y == 0.05)# None? How that? Result should be 56!!
y[56]

# but:
y2 <-as.character(y)
y2[56]
which(y2 == 0.05)

# or rounding alternatively:
which(round(y,2) == 0.05)



More information about the R-devel mailing list