I need a way where gsub (or any other string replacement function) will only replace instances where the entire string is present but nothing else.
e.g.:
String1 <- "FullCosts."
String2 <- "Costs."
Var1 <- "c."
gsub(pattern = String2, replacement = Var1, x = String1)
[1] "FullCosts."
gsub(pattern = String2, replacement = Var1, x = String2)
[1] "c."
instead of what I get at the moment:
gsub(pattern = String2, replacement = Var1, x = String1)
[1] "Fullc."
gsub(pattern = String2, replacement = Var1, x = String2)
[1] "c."
I've also tried playing around with perl = TRUE
but to no success:
gsub(pattern = paste0("\\<",String2,"\\>"), replacement = Var1, x = String1, perl = TRUE)
[1] "FullCosts."
gsub(pattern = paste0("\\<",String2,"\\>"), replacement = Var1, x = String2, perl = TRUE)
[1] "Costs."