[R] Wrong bin count number with hist() ?

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Mon Jan 14 08:32:05 CET 2013


Ken Mailinglist? Sounds like a modern version of the Abbott and Costello "Who's On First" routine.

Anyway, this seems like an excellent opportunity to point out that you can get help on any base or loaded package function using the ? symbol. E.g.

?hist

If you feel the help file is insufficient, please pass along any constructive criticism (or patches to improve it) AFTER you read it carefully. You might also find reading the code informative in some cases... just type the full name of the function at the R command line prompt:

hist.default

Figuring out that you have to add "default" to the name isn't so obvious at first, I must admit, but it is one price we pay in R for being able to do similarly named actions on different kinds of objects.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

ken.mailinglist at me.com wrote:

>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
>
>
>______________________________________________
>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.




More information about the R-help mailing list