[BioC] How to sort a matrix based on its column names andpreserving the identical column names

alex lam (RI) alex.lam at bbsrc.ac.uk
Fri Aug 3 17:47:53 CEST 2007


How about this:

> m<-matrix(runif(30), nr=3)
> colnames(m)<-rep(c("A","B","C","D","E"), 2)
> m
             A         B         C         D         E         A
B
[1,] 0.6603121 0.7788057 0.2465374 0.8624474 0.2542933 0.1170260
0.0810228
[2,] 0.1191780 0.9388283 0.8776471 0.3523432 0.6149786 0.7219005
0.4743703
[3,] 0.3370735 0.6049742 0.9344462 0.7492387 0.2487072 0.5296768
0.7859081
             C          D          E
[1,] 0.5279424 0.30166929 0.69852792
[2,] 0.6352592 0.65057813 0.68920975
[3,] 0.6962578 0.06894764 0.02685270
> m[, order(colnames(m))]
             A         A         B         B         C         C
D
[1,] 0.6603121 0.1170260 0.7788057 0.0810228 0.2465374 0.5279424
0.8624474
[2,] 0.1191780 0.7219005 0.9388283 0.4743703 0.8776471 0.6352592
0.3523432
[3,] 0.3370735 0.5296768 0.6049742 0.7859081 0.9344462 0.6962578
0.7492387
              D         E          E
[1,] 0.30166929 0.2542933 0.69852792
[2,] 0.65057813 0.6149786 0.68920975
[3,] 0.06894764 0.2487072 0.02685270

Cheers,
Alex
------------------------------------
Alex Lam
Roslin Institute (Edinburgh)
Roslin
Midlothian EH25 9PS
Great Britain

Phone +44 131 5274471
Web   http://www.roslin.ac.uk

Roslin Institute is a company limited by guarantee, registered in
Scotland (registered number SC157100) and a Scottish Charity (registered
number SC023592). Our registered office is at Roslin, Midlothian, EH25
9PS. VAT registration number 847380013.

The information contained in this e-mail (including any attachments) is
confidential and is intended for the use of the addressee only.   The
opinions expressed within this e-mail (including any attachments) are
the opinions of the sender and do not necessarily constitute those of
Roslin Institute (Edinburgh) ("the Institute") unless specifically
stated by a sender who is duly authorised to do so on behalf of the
Institute
 

-----Original Message-----
From: bioconductor-bounces at stat.math.ethz.ch
[mailto:bioconductor-bounces at stat.math.ethz.ch] On Behalf Of carol white
Sent: 03 August 2007 13:36
To: bioconductor at stat.math.ethz.ch
Subject: [BioC] How to sort a matrix based on its column names
andpreserving the identical column names

Hello,
How to sort a matrix based on its column names and preserving the
identical column names.

when I use mat [, sort(colnames(mat))], sort changes all column names to
unique ones. for ex,  if the name of 2 columns is col, the 2nd will be
changed to col.1 whereas I want to keep the col name for the two columns

col    col -> col   col.1

thanks

       
---------------------------------
Park yourself in front of a world of choices in alternative vehicles.

	[[alternative HTML version deleted]]

_______________________________________________
Bioconductor mailing list
Bioconductor at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/bioconductor
Search the archives:
http://news.gmane.org/gmane.science.biology.informatics.conductor



More information about the Bioconductor mailing list