[R] Frequency Distribution

Liaw, Andy andy_liaw at merck.com
Wed Aug 9 05:37:09 CEST 2006


You could just do table(cut(...)) and cumsum(table(cut(...))).  See the help
pages for those functions.

Example:

R> x <- rnorm(1e4)
R> breaks <- c(-Inf, -3:3, Inf)
R> table(cut(x, breaks))

(-Inf,-3]   (-3,-2]   (-2,-1]    (-1,0]     (0,1]     (1,2]     (2,3]  (3,
Inf] 
       16       253      1389      3349      3419      1339       220
15 
R> cumsum(table(cut(x, breaks)))
(-Inf,-3]   (-3,-2]   (-2,-1]    (-1,0]     (0,1]     (1,2]     (2,3]  (3,
Inf] 
       16       269      1658      5007      8426      9765      9985
10000 

Andy

From: Michael Zatorsky
> 
> Thankyou William.
> 
> I found the package and read through the documentation.  I'm 
> not a statistican, so it was largely over my head.  I was 
> looking for a command/function that described itself as 
> performing a frequency distribution, and could not find 
> anything obvious enough.
> 
> What did you have in mind in the package that you thought may help? 
> 
> All I'm looking to do is ask it to give me frequencies and 
> cumulative frequencies for the whole dataset, using intervale 
> widths of 100 or 1000 (in much the same way the data would 
> have to have been binned before producing a histogram.
> 
> 
> Regards
> Michael.
> 
> --- William Asquith <wasquith at austin.rr.com> wrote:
> 
> > You might be interested in the lmomco package that supports many 
> > nontraditional and traditional distributions.
> > 
> > William A.
> > 
> > 
> > On Aug 8, 2006, at 9:00 AM, Michael Zatorsky wrote:
> > 
> > > Hi,
> > >
> > > Could someone please suggest where I might find
> > some
> > > instructions / tutorials / FAQs that describe how
> > to
> > > create a frequency distribution and cumulative frequency 
> > > distribution in R using different class withs.
> > >
> > > I have about a 2-million observations (distances between points 
> > > ranging from sub-millimetre to
> > about
> > > 400km, and I want to get a feel for how they are distributed).
> > >
> > > I'd like the output as a table / data rather than
> > an
> > > graph.
> > >
> > > I've searched Google and R's help for obvious
> > terms,
> > > and while I've found much information on graphing/plotting, I 
> > > haven't hit on anything for
> > this.
> > >
> > > (I only downloaded R about 2 hours ago, apologies
> > if
> > > this is obviously documented somewhere I missed.)
> > >
> > > Regards
> > > Michael.
> > >
> > > Send instant messages to your online friends
> > http://
> > > au.messenger.yahoo.com
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch 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.
> > 
> > 
> 
> 
> Send instant messages to your online friends 
> http://au.messenger.yahoo.com
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
> 
>



More information about the R-help mailing list