I have the following df:
structure(list(id = c(9L, 10L, 11L, 96L, 97L, 101L, 103L, 248L,
499L, 1044L), leg_activity = c("home, adpt, shop, car_passenger, home, adpt, work, adpt, home pt,, work pt,, outside, outside, outside pt,, outside pt,, pt, home",
"home pt,, pt, outside, outside, outside, outside pt,, pt, home, car, leisure, car, other, car, leisure, car, leisure, car, other, car, leisure, car, other, car, leisure, car, home, adpt, leisure, adpt, home",
"home pt,, work, adpt, home", "home, car, work, car, home pt,, work, adpt, home",
"home, adpt, work, car_passenger, leisure, car_passenger, work, adpt, home, car_passenger, outside, outside, outside, car_passenger, outside, outside, outside, car_passenger, home",
"home, bike, outside, outside, outside, car_passenger, outside, outside, outside, car_passenger, outside, outside, outside, bike, home, adpt, leisure, adpt, home, bike, leisure, bike, home",
"home, adpt, work, adpt, home, walk, other, pt, home", "home, adpt, work, walk, home, adpt, work, walk, home",
"home, adpt, leisure, adpt, home, bike, outside, outside, outside, bike, home",
"home, pt, work, adpt, home, adpt, work, adpt, home")), row.names = c(NA,
10L), class = "data.frame")
As you can see, the leg_activity column contains strings. What I want is to delete all the words, which are in a connection with the word outside.
To be a bit more specific, lets take hypothetical row as an example:
"home, bike, outside, outside, outside, car_passenger, outside, outside, bike, home, adpt, bike, leisure, bike, home"
The goal is to delete the word that comes before outside as well as the one after outside and eventually, outsideought to be deleted too. The desired output:
"home, home, adpt, bike, leisure, bike, home"
So far I'm only able to delete the specific word
agents$leg_activity <- gsub(', home', '', agents$leg_activity)
Thank you very much for your help!