Thank you all for the suggestions, fantastic!




________________________________
 From: Rui Barradas <ruipbarradas@sapo.pt>

Cc: "r-help@r-project.org" <r-help@r-project.org> 
Sent: Thursday, January 10, 2013 10:32 AM
Subject: Re: [R] sort matrix based on a specific order


Hello,

Try the following. order() gives you a permutation of the vector
    'ind' and to order that permutation gives its inverse.


mat <- cbind(c('w','x','y','z'),c('a','b','c','d'))
ind <- c('c','b','d','a')

ord <- order(ind)
mat[order(ord), ]


Hope this helps,

Rui Barradas

Em 10-01-2013 18:21, array chip escreveu:

Hi I have a character matrix with 2 columns A and B, If I want to sort the matrix based on the column B, but based on a specific order of characters: mat<-cbind(c('w','x','y','z'),c('a','b','c','d'))
ind<-c('c','b','d','a') I want "mat" to be sorted by the sequence in "ind":      [,1] [,2]
[1,] "y"  "c" 
[2,] "x"  "b" 
[3,] "z"  "d" 
[4,] "w"  "a" Is there any simple function that can do this? Thanks John [[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. 
	[[alternative HTML version deleted]]


