[Rd] a fault in the "hist" - function (PR#6931)

stephanschlueter at gmx.de stephanschlueter at gmx.de
Wed Jun 2 11:34:28 CEST 2004


Full_Name: Stephan Schlueter
Version: 1.9.0
OS: 
Submission from: (NULL) (217.184.109.24)


During my studies, I found a fault in the hist()-function:
If you have a vector x with values around zero and also bigger than 10,000,000 ,
there will be a shift of   -max(x)/10,000,000    in the hist-datas.
See my example:

x<-runif(10000)
hist(x,breaks=c(seq(-3,3,0.1)),prob=TRUE)
#everything ok, but now produce the problem 
x[254]=20000000
hist(x,breaks=c(seq(-3,3,0.1),max(x)),prob=TRUE,xlim=c(-3,3))
#here you can see the shift

hist(x + max(x)/10000000,breaks=c(seq(-3,3,0.1),max(x)),prob=TRUE,xlim=c(-3,3))
#first solution (but I don't know ,why it works)

for(i in 1:10000)
 {
 if(x[i]>10)x[i]=10
 }
hist(x,breaks=c(seq(-3,3,0.1),max(x)),prob=TRUE,xlim=c(-3,3))
#second solution (the better one I think)


Good Luck for the solution of this problem, and it would be nice to send me an
answer. 
               Thanks and till then,  Stephan Schlueter



More information about the R-devel mailing list