[R] Is this a bug (or a feature) in hist(x)$density ??
dwinsemius at comcast.net
Sat Mar 13 21:59:06 CET 2010
On Mar 13, 2010, at 3:39 PM, Tal Galili wrote:
> Hi all,
> A friend send me a question on why does this:
> sum( hist(x)$density )
> Gives out "2"
 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
> I tried this:
> sum( hist(x, freq =T)$density )
> It didn't help.
> Then he came back with the following insight:
> # with breaks
> sum(hist(x,breaks=b)$density) # Much more then 2
> # but if we add weights according to the interval length
> sum(hist(x,breaks=b)$density * diff(b))
> # it works
> What do you think ?
I do think that neither you nor your friend understand densities.
David Winsemius, MD
West Hartford, CT
More information about the R-help