HI,
Not sure I understand the last part.
Try this:
dat1<-structure(c(0.585528817843856, 0.709466017509524, 0, -0.453497173462763,
0.605887455840393, -1.81795596770373, 0.630098551068391,
-0.276184105225216,
-0.284159743943371, -0.919322002474128, -0.116247806352002,
1.81731204370422,
0.370627864257954, 0.520216457554957, -0.750531994502331,
0.816899839520583,
-0.886357521243213, -0.331577589942552, 1.12071265166956,
0.298723699267293,
0.779621924555324, 0, -0.644328429231302, -1.55313740522969,
-1.59770951669631, 1.80509751881082, -0.481647363694637, 0.620379801298422,
0.612123492650849, -0.162310976918126, 0.81187317855386, 2.19683354634753,
2.04919033740619, 1.63244563948047, 0.254271192814055, 0.491188279272559,
-0.324086578737118, -1.66205024385863, 1.76773385087297, 0,
1.12851083359018,
-2.38035806139704, -1.06026555215253, 0.937140540182908, 0.854451720330554,
1.46072940310409, -1.4130987778892, 0.567403253424482, 0.583187653435685,
-1.30679883346442), .Dim = c(5L, 10L))
 colnames(dat1)<-paste0("x",1:10)


apply(dat1,2,sort,decreasing=TRUE)
             x1         x2         x3         x4         x5         x6
#[1,]  0.7094660  0.6300986  1.8173120  1.1207127  0.7796219  1.8050975
#[2,]  0.6058875 -0.2761841  0.5202165  0.8168998  0.0000000  0.6203798
#[3,]  0.5855288 -0.2841597  0.3706279  0.2987237 -0.6443284  0.6121235
#[4,]  0.0000000 -0.9193220 -0.1162478 -0.3315776 -1.5531374 -0.1623110
#[5,] -0.4534972 -1.8179560 -0.7505320 -0.8863575 -1.5977095 -0.4816474
            x7         x8         x9        x10
#[1,] 2.1968335  1.7677339  1.1285108  1.4607294
#[2,] 2.0491903  0.4911883  0.9371405  0.5831877
#[3,] 1.6324456  0.0000000  0.8544517  0.5674033
#[4,] 0.8118732 -0.3240866 -1.0602656 -1.3067988
#[5,] 0.2542712 -1.6620502 -2.3803581 -1.4130988


A.K.

----- Original Message -----
From: Nico Met <[email protected]>
To: [email protected]
Cc: 
Sent: Wednesday, August 29, 2012 9:24 AM
Subject: [R] Sorting of columns of a matrix

Dear all,

Please suggest me how can I do it.


I have a matrix which look like following:

  x1 x2 x3  t1 .01 0.3 0  t2 0 0.1 0.01  t3 0 .01 .01  t4 0 0  t5 5 0 0  t6
0 0 0  t7 0 0 0  t8 0 0 0  t9 0.6 0 0  t10 0 0 0.66  t11 0 0.6 0.11  t12 0
0.4 0

I want to sort decreasing order in each column based on rows. and then to
display only those rows which has a value. The expected out put matrix will
look like

  x1 x2 x3  t9 0.6 t11 0.6 t10 0.66  t1 .01 t12 0.4 t11 0.11   t1 0.3 t2 .01
t2 0.1    t3 .01
many thanks

Nico

    [[alternative HTML version deleted]]

______________________________________________
[email protected] 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.


______________________________________________
[email protected] 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.

Reply via email to