[R] Odp: Sort matrix with duplicate row names alphabetically by rowname

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Mon, 19 May 2008 13:31:02 +0200

Hi

r-help-bounces_at_r-project.org napsal dne 19.05.2008 13:06:33:

> Hi,
>
> I've a matrix that contains 4 replicates of each rowname. (4 a's, 4
> b's, 4 c's in no particular order) Like this:
>
>
> #
> c 32
> a 1
> b 4
> c 87
> c 34
> b 54
> a 23
> a 12
> b 9
> a 3
> b 87
> c 43
>
>
> There are a couple of more columns but I'm using the above as an example
>
> I need to sort it so that the same rownames appear together in
> alpahbetical order. Like this:
>
> #
> a 1
> a 23
> a 12
> a 3
> b 4
> b 54
> b 9
> b 87
> c 87
> c 34
> c 43
> c 32
>
>
> The code I came up with is something like this:
>
> mat <- mat[sort(rownames(mat)), ]

Quite close

mat <- mat[order(rownames(mat)), ]

Regards
Petr

>
> This doesn't work though, it returns the same value for each row each
> time, something like this:
>
> #
> a 1
> a 1
> a 1
> a 1
> b 4
> b 4
> b 4
> b 4
> c 32
> c 32
> c 32
> c 32
>
> Any ideas how I could get my code to distinguish between the different
> rows and get the output I'm looking for?
>
> Thanks,
>
> -Paul
>
> ______________________________________________
> 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 - 12:26:55 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 - 13:30:39 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