Hi everyone. I'm currently translating some Matlab code into R. However, I realized that the hsit function produce different results in both languages. in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, but in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1. I'm a bit embarrassed to ask such question, but why R is not producing 10 classes as requested? Thanks in advance,Phil [[alternative HTML version deleted]]
We can just ask hist(): ? hist . . . breaks one of: a vector giving the breakpoints between histogram cells, a function to compute the vector of breakpoints, a single number giving the number of cells for the histogram, =============================================================== a character string naming an algorithm to compute the number of cells (see 'Details'), a function to compute the number of cells. In the last three cases the number is a suggestion only. ======================================================= In this case hist has decided to ignore you. You can overrule by specifying the breaks: hist(1:10, 0:10+.5) ------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of philippe massicotte Sent: Wednesday, September 4, 2013 1:34 PM To: r-help at R-project.org Subject: [R] Histogram Hi everyone. I'm currently translating some Matlab code into R. However, I realized that the hsit function produce different results in both languages. in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, but in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1. I'm a bit embarrassed to ask such question, but why R is not producing 10 classes as requested? Thanks in advance,Phil [[alternative HTML version deleted]] ______________________________________________ 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.
Hello, See the arguments 'right' and 'include.lowest' of ?hist. To give what you want, try instead h1 <- hist(1:10, 10) # counts are 2, 1, 1, ... h2 <- hist(1:10, breaks = 0:10) # all counts are 1 and see the difference between h1 and h2, components 'breaks' and 'counts'. Hope this helps, Rui Barradas Em 04-09-2013 19:34, philippe massicotte escreveu:> Hi everyone. > I'm currently translating some Matlab code into R. However, I realized that the hsit function produce different results in both languages. > in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, but in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1. > I'm a bit embarrassed to ask such question, but why R is not producing 10 classes as requested? > Thanks in advance,Phil > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >