[R] Replacing matching values by related values

Janssen, K.J.M. K.J.M.Janssen at umcutrecht.nl
Sat Sep 17 22:33:04 CEST 2011


I am trying to replace values of a vector (consisting of 15 values) by a value that is related to a matching value in a dataset (consisting of 17 rows).
Here's an example
The vector: 
v <- c(f,a,e,d,m,o,e,f,i,n,e,i,b,a,o)

The dataset's columns consist of the following values
d[,1] <- c(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)
d[,2] <- 1:17

So I want to end up with a vector that consists of the values of the second colomn, when the value of the vector matches the value of the first colomn.
Thus, I aim to end up with a vector with the following values
c(6,1,5,4,13,15,5,6,9,14,5,9,2,1,15)

Help is appreciated!

------------------------------------------------------------------------------

De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is
uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht
ontvangt, wordt u verzocht de inhoud niet te gebruiken en de afzender direct
te informeren door het bericht te retourneren. Het Universitair Medisch
Centrum Utrecht is een publiekrechtelijke rechtspersoon in de zin van de W.H.W.
(Wet Hoger Onderwijs en Wetenschappelijk Onderzoek) en staat geregistreerd bij
de Kamer van Koophandel voor Midden-Nederland onder nr. 30244197.

Denk s.v.p aan het milieu voor u deze e-mail afdrukt.

------------------------------------------------------------------------------

This message may contain confidential information and is...{{dropped:12}}



More information about the R-help mailing list