RE: [R] Frequency table

About this list Date view Thread view Subject view Author view Attachment view

From: Adaikalavan Ramasamy (ramasamy@cancer.org.uk)
Date: Thu 18 Mar 2004 - 02:16:01 EST


Message-id: <ODEPICOHNDBJEHIFCIMPMEHKCBAA.ramasamy@cancer.org.uk>


?data.frame

data.frame( table(cut(x, seq(0, 1, by=0.1))) )

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch]On Behalf Of Kai Hendry
> Sent: 17 March 2004 14:55
> To: r-help@stat.math.ethz.ch
> Subject: [R] Frequency table
>
>
> This must be FAQ, but I can't find it in archives or with a site search.
>
> I am trying to construct a frequency table. I guess this should
> be done with
> table. Or perhaps factor and split. Or prop.table. cut?
> findInterval? Argh!
>
> Please correct me if what I am looking for is not called a
> "frequency table".
> Perhaps it's called grouped data.
>
> > zz$x9
> [1] 65 70 85 65 65 65 62 55 82 59 55 66 74 55 65 56 80 73 45 64
> 75 58 60 56 60
> [26] 65 53 63 72 80 90 95 55 70 79 62 57 65 60 47 61 53 80 75 72
> 87 52 72 80 85
> [51] 75 70 84 60 72 70 76 70 79 72 69 80 62 74 54 58 58 69 81 84
>
> I (think) I want it to look like:
>
> 40-49 2
> 50-59 15
> 60-69 20
> 70-79 19
> 80-89 12
> 90-99 2
>
> Or the other way around with transpose.
>
> classes = c("40-49", "50-59", "60-69", "70-79", "80-89", "90-99")
> For the rownames
>
> sum(zz$x9 > 40 & zz$x9 < 50)
> For getting frequency counts is very laborious...
>
> I got this far:
> > table(cut(zz$x9, brk))
>
> (40,50] (50,60] (60,70] (70,80] (80,90] (90,100]
> 2 19 21 19 8 1
> > brk
> [1] 40 50 60 70 80 90 100
> >
> > t(table(cut(zz$x9, brk)))
> (40,50] (50,60] (60,70] (70,80] (80,90] (90,100]
> [1,] 2 19 21 19 8 1
>
> Still feels a million miles off.
>
> Now I could do with a little help please after spending a couple of hours
> working this out.
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Fri 23 Apr 2004 - 18:36:37 EST