Code Vectorization of gsub in R How can I vectorize this code in R?

data &lt;- data.frame(A = rep(5, 5), B = rep(0, 5))
data$abstract &lt;- c("no abstract available", "A", "A", "B", "no abstract available")

for (row in (1:nrow(data))){
  data [row,"abstract"] &lt;- gsub("no abstract available"," ",data[row,"abstract"])
}
You have plenty of alternatives for this problem


Using sapply

data$abstract &lt;- sapply(data$abstract, 
                        function(x){gsub(pattern = "no abstract available",
                        replacement = " ", x)})

Using mapply

data$abstract &lt;- mapply(gsub, pattern = "no abstract available",
                        replacement = " ", data$abstract)

Using the stringr package

library(stringr)
data$abstract &lt;- str_replace(data$abstract, "no abstract available", 
                             " ")



Also, check this this question on StackOverflow for more information, like solutions with match and the qdap package.