I want to replace just the exact terms in the data dataframe. In the example below, I am trying to replace the word java with xx but it replaces javascript as well as xxscript.
data$new
[1] "xxscript is a statically typed and xx py is a dynamically typed"
[2] "xx is a programming language"
data = data.frame("word"=c('python', 'java'),
"description"=c('Javascript is a statically typed and Python py is a dynamically typed',
'java is a programming language'), stringsAsFactors = FALSE)
ll <- as.list(data$word)
data$new <- data$description
for(i in seq_len(nrow(data))) for(j in seq_along(ll)) {
data$new[i] <- gsub(ll[j], "xx", data$new[i],ignore.case = T)
}
data$new
I am expecting only the exact terms to be replaced.