Re: [R] Replacing values job

2007-11-28 Thread Peter Dalgaard
Barry Rowlingson wrote: > jim holtman wrote: > >> ?match >> >> >>> X >>> >> [1] 2 6 1 7 4 3 5 >> >>> Y >>> >> [1] 1 1 6 4 6 1 4 1 2 3 6 6 1 2 4 4 5 4 1 7 6 6 4 4 7 1 2 >> >>> match(Y,X) >>> >> [1] 3 3 2 5 2 3 5 3 1 6 2 2 3 1 5 5 7 5 3 4 2 2 5 5 4 3 1 >> >>

Re: [R] Replacing values job

2007-11-28 Thread Barry Rowlingson
jim holtman wrote: > ?match > >> X > [1] 2 6 1 7 4 3 5 >> Y > [1] 1 1 6 4 6 1 4 1 2 3 6 6 1 2 4 4 5 4 1 7 6 6 4 4 7 1 2 >> match(Y,X) > [1] 3 3 2 5 2 3 5 3 1 6 2 2 3 1 5 5 7 5 3 4 2 2 5 5 4 3 1 > I quite like this solution: > X[X[X[X[X[X[X[X[X[X[X]][Y] [1] 3 3 2 5 2 3 5 3 1 6

Re: [R] Replacing values job

2007-11-28 Thread Peter Dalgaard
Ingmar Visser wrote: > does this do what you want? > > sapply(y,function(y){which(y==x)}) > Maybe, but match(Y,X) would be more to the point. > hth, Ingmar > > On 28 Nov 2007, at 15:53, Serguei Kaniovski wrote: > > >> Hallo, >> >> I have two vectors of different lengths which contain the sam

Re: [R] Replacing values job

2007-11-28 Thread markleeds
>From: Serguei Kaniovski <[EMAIL PROTECTED]> >Date: 2007/11/28 Wed AM 08:53:34 CST >To: [EMAIL PROTECTED] >Subject: [R] Replacing values job newY<-sapply(1:length(Y), function(.element) match(Y[.element],X)) i hope it helps you. > >Hallo, > >I have two v

Re: [R] Replacing values job

2007-11-28 Thread Ingmar Visser
does this do what you want? sapply(y,function(y){which(y==x)}) hth, Ingmar On 28 Nov 2007, at 15:53, Serguei Kaniovski wrote: > > Hallo, > > I have two vectors of different lengths which contain the same set of > values: > > X < -c(2,6,1,7,4,3,5) > Y <- c(1,1,6,4,6,1,4,1,2,3,6,6,1,2,4,4,5,4,1,7

Re: [R] Replacing values job

2007-11-28 Thread jim holtman
?match > X [1] 2 6 1 7 4 3 5 > Y [1] 1 1 6 4 6 1 4 1 2 3 6 6 1 2 4 4 5 4 1 7 6 6 4 4 7 1 2 > match(Y,X) [1] 3 3 2 5 2 3 5 3 1 6 2 2 3 1 5 5 7 5 3 4 2 2 5 5 4 3 1 > On Nov 28, 2007 9:53 AM, Serguei Kaniovski <[EMAIL PROTECTED]> wrote: > > Hallo, > > I have two vectors of different lengths which

Re: [R] Replacing values job

2007-11-28 Thread Richard . Cotton
> I have two vectors of different lengths which contain the same set of > values: > > X < -c(2,6,1,7,4,3,5) > Y <- c(1,1,6,4,6,1,4,1,2,3,6,6,1,2,4,4,5,4,1,7,6,6,4,4,7,1,2) > > How can I replace the values in Y with the index (!) of the corresponding > values in X. So 2 appears in X in the first

[R] Replacing values job

2007-11-28 Thread Serguei Kaniovski
Hallo, I have two vectors of different lengths which contain the same set of values: X < -c(2,6,1,7,4,3,5) Y <- c(1,1,6,4,6,1,4,1,2,3,6,6,1,2,4,4,5,4,1,7,6,6,4,4,7,1,2) How can I replace the values in Y with the index (!) of the corresponding values in X. So 2 appears in X in the first coordina