Re: [R] sort matrix by sum of columns

2006-06-22 Thread john seers \(IFR\)

Albert

Is this what you want?:

 a[,order(colSums(a))]


John S

 
---


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Albert Vilella
Sent: 21 June 2006 11:38
To: r help
Subject: [R] sort matrix by sum of columns


Hi all,

I would like to know how can I sort the cols of a matrix by the sum of
their elements.


a - matrix(as.integer(rnorm(25,4,2)),10,5)
colnames(a) = c(alfa,bravo,charlie,delta,echo)

I guess I should use colSums, and then rearrange the matrix somehow
according to the result.

My idea is to display a sorted barplot:

barplot(a, horiz=TRUE, legend.text=T)

Thanks in advance,

Albert.

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] sort matrix by sum of columns

2006-06-21 Thread Albert Vilella
Hi all,

I would like to know how can I sort the cols of a matrix by the sum of
their elements.


a - matrix(as.integer(rnorm(25,4,2)),10,5)
colnames(a) = c(alfa,bravo,charlie,delta,echo)

I guess I should use colSums, and then rearrange the matrix somehow
according to the result.

My idea is to display a sorted barplot:

barplot(a, horiz=TRUE, legend.text=T)

Thanks in advance,

Albert.

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


Re: [R] sort matrix by sum of columns

2006-06-21 Thread Dimitris Rizopoulos
probably you're looking for ?order(), e.g.,

barplot(a[, order(colSums(a))], horiz = TRUE, legend.text = TRUE)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: Albert Vilella [EMAIL PROTECTED]
To: r help r-help@stat.math.ethz.ch
Sent: Wednesday, June 21, 2006 12:38 PM
Subject: [R] sort matrix by sum of columns


 Hi all,

 I would like to know how can I sort the cols of a matrix by the sum 
 of
 their elements.


 a - matrix(as.integer(rnorm(25,4,2)),10,5)
 colnames(a) = c(alfa,bravo,charlie,delta,echo)

 I guess I should use colSums, and then rearrange the matrix somehow
 according to the result.

 My idea is to display a sorted barplot:

 barplot(a, horiz=TRUE, legend.text=T)

 Thanks in advance,

Albert.

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


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] sort matrix by sum of columns

2006-06-21 Thread Petr Pikal
Hi

order is your friend


On 21 Jun 2006 at 11:38, Albert Vilella wrote:

From:   Albert Vilella [EMAIL PROTECTED]
To: r help r-help@stat.math.ethz.ch
Date sent:  Wed, 21 Jun 2006 11:38:17 +0100
Subject:[R] sort matrix by sum of columns
Send reply to:  [EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]

 Hi all,
 
 I would like to know how can I sort the cols of a matrix by the sum of
 their elements.
 
 
 a - matrix(as.integer(rnorm(25,4,2)),10,5)
 colnames(a) = c(alfa,bravo,charlie,delta,echo)

 ord-order(colSums(a))
 barplot(a[,ord], horiz=TRUE, legend.text=T)

HTH
Petr



 
 I guess I should use colSums, and then rearrange the matrix somehow
 according to the result.
 
 My idea is to display a sorted barplot:
 
 barplot(a, horiz=TRUE, legend.text=T)
 
 Thanks in advance,
 
 Albert.
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html

Petr Pikal
[EMAIL PROTECTED]

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