I am trying to partially replace text within a string called "string1".
There are multiple patterns contained in "LocateMe" which I would like to look for and replace with the same string of text: "!= -9999"
The multiple patterns are quite complex containing special characters such as "=" and "["
Is it possible to achieve this using gsub
or should I be using another function? Any guidance would be greatly appreciated.
string1 <- "Birth == unique.combos[17,1] & hid_age == unique.combos[17,2] & z02_gender == unique.combos[17,3]"
LocateMe <- c("== unique.combos[37,1]", "== unique.combos[38,1]", "== unique.combos[39,1]", "== unique.combos[40,1]", "== unique.combos[41,1]", "== unique.combos[42,1]",
"== unique.combos[17,1]", "== unique.combos[17,3]", "== unique.combos[18,3]")
string2 <- gsub(LocateMe, "!= -9999", string1)