Hello john,

thanks for the suggestion. Please find an example:

> X<-matrix(rnorm(5*10),nrow=5)

> dim(X)
[1]  5 10
> X
           [,1]       [,2]        [,3]       [,4]       [,5]       [,6]
   [,7]       [,8]       [,9]      [,10]
[1,]  1.2774431 -1.2427735  0.81933548 -2.1098586 -1.6726799 -2.2994684
-0.28823228  0.1929301  0.1187168 -1.2078372
[2,]  0.5969187 -1.2571336  0.30292368 -0.2098139 -0.9689961  1.7105109
 0.77240398  0.1482712 -1.2486152  0.2359723
[3,] -0.9669289 -0.2315229  1.04611417  0.7902772  0.5791674  0.6296305
-0.60517647  0.5317435 -0.2556417 -0.4838956
[4,] -1.9345400  0.2898647  0.08983352  0.1482130  0.8229054  0.7778114
 0.49423641  0.4015327  2.8596603  0.6618432
[5,] -1.1969226 -1.3991657 -0.76507258  0.5024922  0.2633307  0.0236774
-0.09497448 -0.3986624  0.1327156 -0.8935923

> X[2,5]<-0
> X[3,1]<-0
> X[6,8]<-0
> X[5,8]<-0
> X
           [,1]       [,2]        [,3]       [,4]       [,5]       [,6]
   [,7]      [,8]       [,9]      [,10]
[1,]  1.2774431 -1.2427735  0.81933548 -2.1098586 -1.6726799 -2.2994684
-0.28823228 0.1929301  0.1187168 -1.2078372
[2,]  0.5969187 -1.2571336  0.30292368 -0.2098139  0.0000000  1.7105109
 0.77240398 0.1482712 -1.2486152  0.2359723
[3,]  0.0000000 -0.2315229  1.04611417  0.7902772  0.5791674  0.6296305
-0.60517647 0.5317435 -0.2556417 -0.4838956
[4,] -1.9345400  0.2898647  0.08983352  0.1482130  0.8229054  0.7778114
 0.49423641 0.4015327  2.8596603  0.6618432
[5,] -1.1969226 -1.3991657 -0.76507258  0.5024922  0.2633307  0.0236774
-0.09497448 0.0000000  0.1327156 -0.8935923



Now I want to sort and remove "zero" based on rows.

for example for column 1:

[1,]1.2774431

[2,]0.5969187

[5,]-1.1969226

[4,]-1.9345400


Regards

Nico

On Wed, Aug 29, 2012 at 3:29 PM, John Kane <jrkrid...@inbox.com> wrote:

> Perhaps you could supply the matrix using dput() ?  It is a handy way to
> supply sample data.  Just do dput(mydata), copy the results and paste into
> email.
>
> At the moment your matrix is almost unreadable.
>
> John Kane
> Kingston ON Canada
>
>
> > -----Original Message-----
> > From: nicome...@gmail.com
> > Sent: Wed, 29 Aug 2012 15:24:17 +0200
> > To: r-help@r-project.org
> > 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]]
> >
> > ______________________________________________
> > 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.
>
> ____________________________________________________________
> FREE ONLINE PHOTOSHARING - Share your photos online with your friends and
> family!
> Visit http://www.inbox.com/photosharing to find out more!
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to