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 [[alternative HTML version deleted]]
For simply counting frequency of discrete data, table , xtabs, and ftable will work.> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] > On Behalf Of Khanh Nguyen > Sent: Thursday, October 08, 2009 2:47 PM > To: r-help at r-project.org > Subject: [R] histogram > > 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 > > [[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.
Change the breaks argument: t1 <- hist(1:5, 0:5) t1$counts On Thu, Oct 8, 2009 at 4:47 PM, Khanh Nguyen <knguyen at 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 > > ? ? ? ?[[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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
On Oct 8, 2009, at 3:47 PM, Khanh Nguyen 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' ?It depends on the way the bins are defined. Had you forced a particular set of breaks you would get a different set of bin boundaries. t1 <- hist(c(1,2,3,4,5), breaks=c(1,2,3,4,5,6)-.1)> > Is there any other function to count frequency of discrete data??table > table(c(1,2,3,4,5)) 1 2 3 4 5 1 1 1 1 1> Thanks. > > -k > > [[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.David Winsemius, MD Heritage Laboratories West Hartford, CT
On 9/10/2009, at 8:47 AM, Khanh Nguyen 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?RTFM --- include.lowest = TRUE and right = TRUE by default.> And should the counts be '1 1 1 1 1' ?No. Not unless you specify different breaks.> Is there any other function to count frequency of discrete data?table() cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
Dear R developers,How I can build a histogram from matrix: 0 0.5 1 0.25 34 43 65 1 23 35 54 4 22 29 42 10 21 22 29 20 15 17 20 (first string is represented names of columns, first column is represented names of rows) where names of columns should be x-axis labels; respectively to this, I want to have three groups of bars (5 bars in each group)? Y values should be represented by values given in the "core" of matrix. Names of the rows should be in a legend, and should represent the each of 5 bars (in group) name. I would also try to build filled contour, however, i can't "ask" the program to consider column and rownames like true values, not only like labels. So, column names should be the y-values, while row names should be the x-values. Values placed in the "core" of matrix should be z-values. With regard, Dmitry.