[R] Wrong bin count number with hist() ?
ken.mailinglist at me.com
ken.mailinglist at me.com
Mon Jan 14 03:49:52 CET 2013
Hi there,
# Consider the following example:
A = 19
B = 20
A< B
A==B
hist(c(1:15,B,50),breaks=c(0,15,A,50),plot=F)$count
hist(c(1:15,A,50),breaks=c(0,15,B,50),plot=F)$count
# I was expecting the same results with the following values of A and B:
A = 19.6019203953960
B = 19.6019204365543
A< B
A==B
hist(c(1:15,B,50),breaks=c(0,15,A,50),plot=F)$count# wrong
hist(c(1:15,A,50),breaks=c(0,15,B,50),plot=F)$count# correct
# Note that truehist() of MASS define the bin count number "correctly"
require(MASS)
par(mfrow=c(1,2))
hist(c(1:15,B,50),breaks=c(0,15,A,50),col="light gray",main="wrong - hist()")
truehist(c(1:15,B,50),breaks=c(0,15,A,50),main="correct - truehist()")
# I was not able to find an explanation online or in the R documentation.
# The option "include.lowest" doesn't help in such cases.
# Any clue to get the correct count number per bin ?
Regards,
Ken
More information about the R-help
mailing list