[R] Replacing values job
Peter Dalgaard
P.Dalgaard at biostat.ku.dk
Wed Nov 28 18:19:21 CET 2007
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
>>
>>
>
> 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 2 2 3 1 5 5 7 5 3 4 2 2 5 5 4 3 1
>
> but somehow I don't think its general enough...
>
!!
<Grin>
order(X)[Y]
is a little more general. Still only works when X is a permutation of
1:N, of course.
> Barry
>
> ______________________________________________
> R-help at 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.
>
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list