[R] sum(hist$density) == 2 ?!

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Wed Mar 14 07:13:19 CET 2012


Your clue is... density!

Probability density is not the same as probability... you have to multiply it by something before you can sum it.

Try typing

h

by itself and review your options.
---------------------------------------------------------------------------
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.

Sam Steingold <sds at gnu.org> wrote:

>> x <- rnorm(1000)
>> h <- hist(x,plot=FALSE)
>> sum(h$density)
>[1] 2 ----------------------------- shouldn't it be 1?!
>
>> h <- hist(x,plot=FALSE, breaks=(-4:4))
>> sum(h$density)
>[1] 1  ----------------------------- now it's 1. why?!
>
>
>
>-- 
>Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X
>11.0.11004000
>http://www.childpsy.net/ http://www.memritv.org
>http://openvotingconsortium.org
>http://thereligionofpeace.com http://mideasttruth.com
>http://palestinefacts.org
>((lambda (x) `(,x ',x)) '(lambda (x) `(,x ',x)))
>
>______________________________________________
>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