Skip to content

Ordering a matrix based on cluster no

4 messages · John Kane, Aparna Sampath

#
Combine the two matrices into one data.frame and order them
Example done using data.frames rather than matrices but just use use data.frame(x,y) to convert to a data.frame

bmat <- data.frame(matrix(1:25,5))
smat <- data.frame(aa= LETTERS[1:25],
       bb = rep(c("a","b","c", "d", "e"),5))
df1  <- data.frame(smat, bmat)
orddata  <- df1[order(df1[,2],decreasing=TRUE),]

I hope this helps.
--- On Sun, 6/26/11, Aparna Sampath <aparna.sampath26 at gmail.com> wrote:

            
#
Thanks for the help! But when I tried it, it does not work the same way I
want. :(
 after combining the two matrices, they look like this:


             V1            V2               X           TEL.AML1.C41  
Hyperdip.50.C23
1     TEL.AML1.C41   1    TEL.AML1.C41       1.0000000      0.00000000
2  Hyperdip.50.C23   1    Hyperdip.50.C23    0.0000000      1.00000000
3       BCR.AB.LC1    1    BCR.AB.LC1           0.1212121      0.78125000
4  Hyperdip.50.C13   1    Hyperdip.50.C13    0.0000000      1.00000000
6       TEL.AML1.9    1    T.ALL.C5              0.0000000      0.03225807
7       TEL.AML1.8    1    TEL.AML1.9          1.0000000      0.00000000
8   Hyperdip.50.C7    1   TEL.AML1.8           1.0000000      0.00000000
9     TEL.AML1.C37   1   Hyperdip.50.C7       0.0000000      1.00000000
11    TEL.AML1.C47  1   TEL.AML1.C37        1.0000000      0.00000000
13  Hyperdip.50.11   1   MLL.6                    0.0000000      0.03225807


when i do :  orddata1  <- df2_a[order(df2_a[,1],decreasing=T),] 

I get the result:

           V1           V2                   X           TEL.AML1.C41
Hyperdip.50.C23
22   TEL.AML1.C49   1       TEL.AML1.2M.1            1          0.00000000
11   TEL.AML1.C47   1       TEL.AML1.C37              1         0.00000000
1    TEL.AML1.C41   1        TEL.AML1.C41             1          0.00000000
9    TEL.AML1.C37   1        Hyperdip.50.C7            0          1.00000000
6    TEL.AML1.9      1        T.ALL.C5                     0        
0.03225807
7    TEL.AML1.8      1        TEL.AML1.9                 1        
0.00000000
16  TEL.AML1.2M.4  1        Hyperdip.50.11            0         1.00000000
19  TEL.AML1.2M.1  1        TEL.AML1.2M.4            1         0.00000000
15  Hyperdip.50.R2  1        T.ALL.C10                   0        
0.00000000
20  Hyperdip.50.C9  1        BCR.ABL.Hyperdip.R5     0         1.00000000


The results are not right! I want it to look for the gene TEL.AML1.C49 in
the second matrix and group it accordingly. 

Aparna 

--
View this message in context: http://r.789695.n4.nabble.com/Ordering-a-matrix-based-on-cluster-no-tp3625956p3627017.html
Sent from the R help mailing list archive at Nabble.com.
#
Hi
First a handy point : When supplying sample data it is a good idea to use dput(). See ?dput for an explanation.  It makes it much easier to see what the data looks like and to work with it.  Sample data pasted into a e-mail can get badly mangled.  Yours was not bad but still need a bit of cleaning up.  I think I'll suggest that this idea goes in the posting guidelines.

Next point: Do you really have two matrices? It looks from the examples you have supplied that you have two data.frames unless all the numerics in the two data sets actually are character values.  Try str(data.set) to see what they are.

On to more substantive matters.  It looks like I misread part of the post. I had assumed that both the 100 X 100 matrix and the 2 X 100 were sorted already and just needed to be joined and sorted.

It looks to me like what you want to do is to merge (?merge for info)  the two data sets based on the gene names (in merge they should have the same variable name to make life easy ) and then apply the order command to sort by cluster

Of the top of my head, and using the example names I used earlier  I thin;k you want something like  this assuming a common name for the gene name.

merge (smat, bmat,  by= ?gene?)  # untested

Then apply the order command.

I hope I understood the problem this time
--- On Mon, 6/27/11, Aparna Sampath <aparna.sampath26 at gmail.com> wrote: