Dear R-help-list

I have two character vectors

a <- c("A", "B", "C")
b <- c("A", "C", "B")

Then

sapply(a, function(i) grep(i, b))

computes the permutation of the entries in 'b' needed
to bring 'b' into the same order as 'a'.

I have searched around, but haven't been able to find
any existing function that compute this permutation.
Is there such a function doing this -- perhaps more
efficiently than the above?

For those interested, I need the permutation to bring
the rows of a data frame into the same order as the
levels of a factor.

Thanks, Niels

--
Niels Richard Hansen                     Web:   www.math.ku.dk/~richard 
Associate Professor                      Email: niels.r.han...@math.ku.dk
Department of Mathematical Sciences             nielsrichardhan...@gmail.com
University of Copenhagen                 Skype: nielsrichardhansen.dk   
Universitetsparken 5                     Phone: +45 353 20783 (office)  
2100 Copenhagen Ø                               +45 2859 0765 (mobile)
Denmark

______________________________________________
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