[R] How to sort frequency distribution table?
John Kane
jrkrideau at inbox.com
Thu Mar 8 16:05:35 CET 2012
Here is a quick start. You will have to either greatly reduce the length of the names or play around with various plot or barplot options to get the x labels.
Have a look at ?plot.default and ?barplot for more information
John Kane
Kingston ON Canada
================================================
aa <- c("Acute lymphoblastic leukemia (childhood)",
"Adiponectin levels",
"Adiponectin levels",
"Adiponectin levels",
"Adiponectin levels",
"Adiponectin levels",
"Adiposity",
"Adiposity",
"Adiposity",
"Adiposity",
"Age-related macular degeneration",
"Age-related macular degeneration",
"Aging (time to death)",
"Aging (time to event)",
"Aging (time to event)",
"Aging (time to event)",
"Aging (time to event)",
"AIDS",
"AIDS",
"AIDS")
(xx <- table(aa))
barplot(xx)
=================================================
> -----Original Message-----
> From: mandecent.gupta at gmail.com
> Sent: Wed, 7 Mar 2012 20:46:18 -0800 (PST)
> To: r-help at r-project.org
> Subject: [R] How to sort frequency distribution table?
>
> Hi,
>
> I am working on categorical data with column as disease name(categaory).
>
> My input data is
> [1] Acute lymphoblastic leukemia (childhood)
> [2] Adiponectin levels
> [3] Adiponectin levels
> [4] Adiponectin levels
> [5] Adiponectin levels
> [6] Adiponectin levels
> [7] Adiposity
> [8] Adiposity
> [9] Adiposity
> [10] Adiposity
> [11] Age-related macular degeneration
> [12] Age-related macular degeneration
> [13] Aging (time to death)
> [14] Aging (time to event)
> [15] Aging (time to event)
> [16] Aging (time to event)
> [17] Aging (time to event)
> [18] AIDS
> [19] AIDS
> [20] AIDS
> .....
>
>
> when i use table command, i get
>
>
> [,1]
> Acute lymphoblastic leukemia (childhood) 1
> Adiponectin levels
> 5
> Adiposity
> 4
> Age-related macular degeneration
> 2
> Aging (time to death)
> 1
> ......
>
> But i need to sort this table by frequency and need to plot a histogram
> with
> lable first column (e.g. Adiposity , Age-related macular degeneration as
> bar name). How can i do it?
>
> Regards
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/How-to-sort-frequency-distribution-table-tp4455595p4455595.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
More information about the R-help
mailing list