[R] Counting frequency within each range
David L Carlson
dcarlson at tamu.edu
Fri Jul 27 03:46:49 CEST 2012
table(cut(numbers, c(0, 10, 20, 30, . . .), include.lowest=TRUE))
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Chintanu
> Sent: Thursday, July 26, 2012 8:23 PM
> To: r-help at r-project.org
> Subject: [R] Counting frequency within each range
>
> Hi,
>
> This is a simple problem, but for the life of me I cannot find the
> answer.
> How to determine frequency within given ranges ?
> I know that table() gives frequency, for example
>
> a <- table(numbers)
> > a
> numbers
> 4 5 23 34 43 54 56 65 67 324 435 453 456 567 657
> 2 1 2 2 1 1 2 1 2 1 3 1 1 1
> 1
>
> > as.data.frame(table(numbers))
> numbers Freq
> 1 4 2
> 2 5 1
> 3 23 2
> 4 34 2
> ...
>
> However, there must be some simple way to get the frequency based on
> ranges, such as 0-10, 10-20, 20-30 and so on.
> Please help !
>
> Thank you.
>
> Cheers,
> Chintanu
>
> [[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.
More information about the R-help
mailing list