[R] sorting table output

2009-10-21 Thread Erin Hodgess
Dear R People:

Suppose I have the following output:

 table(xx)
xx
 A  C  G  T
13 12 10 15


I would like to have the output sorted in descending order by height
or frequency.

But when I do the following:

 rev(table(xx))
xx
 T  G  C  A
15 10 12 13


the output is sorted by the names rather than the frequency.

Any suggestions, please?

Thanks in advance,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

__
R-help@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.


Re: [R] sorting table output

2009-10-21 Thread Stefan Evert

I would like to have the output sorted in descending order by height
or frequency.

But when I do the following:


rev(table(xx))

xx
T  G  C  A
15 10 12 13





Err, I guess you meant to write

sort(table(xx))

here?

Cheers,
Stefan

__
R-help@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.


Re: [R] sorting table output

2009-10-21 Thread Rolf Turner


On 22/10/2009, at 11:16 AM, Erin Hodgess wrote:


Dear R People:

Suppose I have the following output:


table(xx)

xx
 A  C  G  T
13 12 10 15


I would like to have the output sorted in descending order by height
or frequency.

But when I do the following:


rev(table(xx))

xx
 T  G  C  A
15 10 12 13




the output is sorted by the names rather than the frequency.

Any suggestions, please?


(a) Why on earth are you using ***rev()***???

(b) Does this do what you want?

 tx - table(xx)
 tx[order(tx)]
xx
G  C  A  T
10 12 13 15

cheers,

Rolf


##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@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.