[R] subbing a string vector for another string vector

jlemaitre josh at richrelevance.com
Wed Sep 8 22:45:19 CEST 2010


I have a data frame with two columns:
      image                               pattern
1    http://$IMAGE_ID$            www.url.com/image.jpg
2    $IMAGE_ID$                      http://www.blah.com/image.gif
...

I want to replace "$IMAGE_ID$" with the corresponding entry in the pattern
column such that the result would appear as follows:

url
http://www.url.com/image.jpg
http://www.blah.com/image.gif

Using something like  > gsub("\\$IMAGE\\_ID\\$",image,pattern) doesn't work
because it only takes uses the first entry in "pattern" as the replacement
for all "image" entries:

url
http://www.url.com/image.jpg
www.url.com/image.jpg

Please help.
Thanks.




-- 
View this message in context: http://r.789695.n4.nabble.com/subbing-a-string-vector-for-another-string-vector-tp2532005p2532005.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list