[R] Recode numbers

Duncan Murdoch murdoch.duncan at gmail.com
Wed Jun 1 20:50:50 CEST 2011


(The attributions are a little messed up here:)

>> I have two sets of numbers that look like
>>> a<- c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, 3,
>>> 4)
>>>
>>> b<- c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15,
>>> 19)
>>>
>>> I just want to use “b” to encode “a” so that “a” looks like
>>>
>>> a1<- c(1, 5, 8, 8, 9, 9, 14, 20, 3, 10, 10, 12, 6, 16, 7, 11, 13, 13, 17,
>>> 18, 2, 4, 15, 19)
>>>
>>> Does anyone have a suggestion how to deal with this? Thank you in advance.
>>>
>>
>> is a1 = b[a] what you are looking for?
>>
>> HTH
>>
>> Pete
>
> Thank you for your help, Pete. I tried b[a], but it is not a1.


I think you'll need to explain the rule used for a1[9], a1[10], etc.

Duncan Murdoch



More information about the R-help mailing list