Henrique Dallazuanna wrote:
Change the breaks argument:

t1 <- hist(1:5, 0:5)
t1$counts

On Thu, Oct 8, 2009 at 4:47 PM, Khanh Nguyen <kngu...@cs.umb.edu> wrote:
Hi all,

I have a question about hist()

1)
t1 <- hist(c(1,2,3,4,5))
t1
$breaks
[1] 1 2 3 4 5

$counts
[1] 2 1 1 1

why is there 2 counts for 1? And should the counts be '1 1 1 1 1' ?

Is there any other function to count frequency of discrete data?

Thanks.

-k


Nobody has mentioned what I think is the important point here, that histogram is not intended for the purpose of dealing with discrete data. To expect that it will give you the counts you want is just wrong. As others have pointed out if you make things more explicit and don't take the defaults it will do so.

Using hist to obtain counts like this is like using a hammer to drive in a screw.

David Scott

--
_________________________________________________________________
David Scott     Department of Statistics
                The University of Auckland, PB 92019
                Auckland 1142,    NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

______________________________________________
R-help@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.

Reply via email to