[R] The permutation of one vector into another

2010-09-16 Thread Niels Richard Hansen
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

Re: [R] The permutation of one vector into another

2010-09-16 Thread Michael Bedward
match(b, a) ? Michael On 16 September 2010 17:13, Niels Richard Hansen niels.r.hansen+li...@math.ku.dk wrote: 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

Re: [R] The permutation of one vector into another

2010-09-16 Thread Niels Richard Hansen
match(b, a) ? Michael Right! Thanks, Michael. On 16 September 2010 17:13, Niels Richard Hansen niels.r.hansen+li...@math.ku.dk wrote: 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

Re: [R] The permutation of one vector into another

2010-09-16 Thread David Winsemius
On Sep 16, 2010, at 4:23 AM, Michael Bedward wrote: match(b, a) ? Or just order(.) : b[order(a)] [1] A C B -- David Michael On 16 September 2010 17:13, Niels Richard Hansen niels.r.hansen+li...@math.ku.dk wrote: Dear R-help-list I have two character vectors a - c(A, B, C) b - c(A,