Skip to content
Prev 36400 / 63424 Next

hist.default()$density

Dear developers,

since running 'example(hist)' produces
...
hist> sum(r$density * diff(r$breaks)) # == 1
[1] 0.9999999
...
I suppose that the current behaviour of hist() is not as intended (and 
documented).
So, please find attached (and inline below) a (trivial) patch for 
hist.default().

Best wishes
  Martin


Index: src/library/graphics/R/hist.R
===================================================================
--- src/library/graphics/R/hist.R    (revision 51652)
+++ src/library/graphics/R/hist.R    (working copy)
@@ -111,7 +111,7 @@
     stop("negative 'counts'. Internal Error in C-code for \"bincount\"")
     if (sum(counts) < n)
     stop("some 'x' not counted; maybe 'breaks' do not span range of 'x'")
-    dens <- counts/(n*h)
+    dens <- counts/(n*diff(breaks))
     mids <- 0.5 * (breaks[-1L] + breaks[-nB])
     r <- structure(list(breaks = breaks, counts = counts,
             intensities = dens,
Martin Becker wrote: