[Rd] weird breaks in hist (PR#2431)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Wed Jan 8 14:45:04 2003


I am baffled as to why you think there is a bug in R here!

On Wed, 8 Jan 2003 reinhold.koch@unibas.ch wrote:

> Full_Name: Reinhold Koch
> Version: 1.6.1
> OS: redhat 8.0
> Submission from: (NULL) (131.152.84.111)
>
>
> I came across rather weird behavior of the breaks in hist:
>
> hist(1:3)
>
> gives the expected result, besides an unnecessary gap between 2nd and 3rd
> column

It gives the expected result, period.  There is no gap, but there is a bin
with count zero.

> hist(1:4)
>
> always merges up the first two columns,

Why is that wierd?  You requested three bins and that's what you got.
(If you didn't know you had done that, please read the help page.)

> also if I resort to
> hist.default(1:4,breaks=1:4). hist.default(1:4, include.lowest=F) gives an
> error:
>
> Error in hist.default(1:4, include.lowest = F) :
>         some `x' not counted; maybe `breaks' do not span range of `x'

Why do you even mention that?  It's correct!  The breaks chosen are
to cover a prettified range of x.  You explicitly asked for left-open
intervals, so you got

(1,2], (2,3], (3,4]

and those do not cover the data.

Perhaps as idiot-proofing, include.lowest should not be allowed unless
`breaks' is a sequence of breakpoints.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595