text = c("Hello abc01","Go to abc02")
value = c(0,1)
symbol=c("abc01","abc02")
df1 = data.frame(text)
df2 = data.frame(symbol,value)
I want to replace the symbols contained as text in df1 with the corresponding value in df2, to obtain: 'Hello 0', 'Go to 1'
.
Typically for string-replacement I used gsub(pattern, replacement, x)
Ex: If I want to replace "abc01" and "abc02" with "OK":
df1 = apply(df1,2,function(x) gsub("abc[0-9]{2}","OK",x))
My idea is to use a function in replace section:
gsub(df1,2,function(x) gsub("(abc)", Support(KKK),x)
in which I'll do the substitution, but I don't know how I can passing as argument KKK, the matching-strings determined(abc01,abc02).