I need to remove a series of substrings from a vector, that might or might not occur multiple times. The substrings to drop are less than the number of strings.
I would like to use a loop but gsub seems to fail in a for loop.
drop <- c("red ","blue ","yellow ")
auto <- data.frame(entry=c("red car","red yellow car","car"))
for(i in 1:length(drop)){
auto$entry_simple <- gsub(drop[i],"",auto$entry)
}
The loops works only for the last entry how? This is the result
entry entry_simple
1 red car red car
2 red yellow car red car
3 car car
Instead of
entry entry_simple
1 red car car
2 red yellow car car
3 car car