[R] How to sort frequency distribution table?
Jim Lemon
jim at bitwrit.com.au
Thu Mar 8 11:25:25 CET 2012
On 03/08/2012 03:46 PM, Manish Gupta wrote:
> 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?
>
Hi Manesh,
The freq function (prettyR) returns a vector (or a list of vectors if
more than one variable is passed) with the same information as the table
function. However, freq orders the table in descending frequency by default.
Jim
More information about the R-help
mailing list