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
>>
>>
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
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
>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
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
?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
> 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
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
8 matches
Mail list logo