My code has a for loop that is taking ages for running. I was wondering how can speed up it by using one of the apply family functions available in R.
The for loop that I want to change would look like this:
for (i in range(1:200000)){
a[i] = gsub(pattern[i],new_pattern[i])
}
Where pattern and new_pattern are both lists. What I want to achieve is to change a character pattern in each line for a new one. I have tried the following:
sapply(c(1:200000),function(x) gsub(pattern[x],new_pattern[x], a[x]))
But it is taking very long too. Any suggestions of how can I improve my code to be faster?