library(stringr)
library(dplyr)
DF <- data.frame(Text= c("cat_loves_dog",
"dog_love_cat",
"me_ow_sith_love",
"animal_cat_do",
"dog_love_kiss",
"monkey_see_do"))
DF <- DF |>
mutate(data_manip = str_remove(str_extract(Text, "_[^_]+$"),"^_do$"))
DF
Text data_manip
1 cat_loves_dog _dog
2 dog_love_cat _cat
3 me_ow_sith_love _love
4 animal_cat_do
5 dog_love_kiss _kiss
6 monkey_sith_see_do
above is my final dataset. I want to create a column called text_new which removes the string in data_manip from the string in text... but also removes any mention of the word "Sith" and its preceding hyphen "" and the word "Lime" and its preceding hyphen "".
note if there is no string in "data_manip" it should be appearing as is. unless there is the word "sith" or "lime" of course. thank u so very much. What I want:
Text data_manip text_new
1 cat_loves_dog _dog cat_love
2 dog_love_cat _cat dog_love
3 me_ow_sith_love _love me_ow
4 animal_cat_do animal_cat_do
5 dog_love_kiss _kiss dog_love
6 monkey_sith_see_do monkey_see_do