Re: [R] Rank Values in a Matrix

From: Doran, Harold <HDoran_at_air.org>
Date: Mon, 19 May 2008 08:22:41 -0400


Whoops, I inadvertently created a dataframe called aa and not a matrix, so the code below assumes aa is a dataframe and not a matrix.

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Doran, Harold
> Sent: Monday, May 19, 2008 8:15 AM
> To: Jens Oldeland; r-help_at_stat.math.ethz.ch
> Subject: Re: [R] Rank Values in a Matrix
>
> If your matrix below is called aa, you could do this
>
> > matrix(rank(aa, ties='min'), ncol=ncol(aa))
> [,1] [,2] [,3] [,4]
> [1,] 4 8 1 11
> [2,] 14 11 11 5
> [3,] 15 5 5 1
> [4,] 15 8 8 1
>
> This doesn't assign the values you list, but it does rank
> them. OTOH, if you want as you have below, I think this works
>
> rank(unique(stack(aa)[1]))-1
>
> > -----Original Message-----
> > From: r-help-bounces_at_r-project.org
> > [mailto:r-help-bounces_at_r-project.org] On Behalf Of Jens Oldeland
> > Sent: Monday, May 19, 2008 7:47 AM
> > To: r-help_at_stat.math.ethz.ch
> > Subject: [R] Rank Values in a Matrix
> >
> > Dear All,
> >
> > a short and maybe simple question:
> >
> >
> > I have to rank all values in a matrix from 0 to X,
> >
> > [1] [2] [3] [4]
> > [1] 0.1 2 0 3
> > [2] 50 3 3 1
> > [3] 100 1 1 0
> > [4] 100 2 2 0
> >
> > 0->0
> > 0.1->1
> > 2->2
> > 3->3
> > 50->4
> > 100->5 (X=5)
> >
> > is there any function for this? i have looked in several packages
> > (vegan, labdsv etc.) because I am working with species by
> site tables,
> > but without success. perhaps I looked for the wrong terms
> (rank matrix
> > etc.)
> >
> > thank you for your help
> >
> > regards,
> > Jens
> >
> > --
> > +++++++++++++++++++++++++++++++++++++++++
> > Dipl.Biol. Jens Oldeland
> > University of Hamburg
> > Biocentre Klein Flottbek and Botanical Garden Ohnhorststr. 18
> > 22609 Hamburg,
> > Germany
> >
> > Tel: 0049-(0)40-42816-407
> > Fax: 0049-(0)40-42816-543
> > Mail: Oldeland_at_botanik.uni-hamburg.de
> > Jens.Oldeland_at_DLR.de (for attachments > 2mb!!)
> > http://www.biologie.uni-hamburg.de/bzf/fbda005/fbda005.htm
> > +++++++++++++++++++++++++++++++++++++++++
> >
> > ______________________________________________
> > R-help_at_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.
> >
>
> ______________________________________________
> R-help_at_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.
>



R-help_at_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. Received on Mon 19 May 2008 - 13:02:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 19 May 2008 - 15:00:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive