【发布时间】:2018-05-14 12:42:36
【问题描述】:
这是一个示例数据框:
a <- c("cat", "dog", "mouse")
b <- c("my cat is a tabby cat and is a friendly cat", "walk the dog", "the mouse is scared of the other mouse")
df <- data.frame(a,b)
我希望能够删除 col b 中 col a 中第二次出现的值。
这是我想要的输出:
a b
cat my cat is a tabby and is a friendly cat
dog walk the dog
mouse the mouse is scared of the other
我已经尝试过 gsub 和一些 stringr 函数的不同组合,但我什至还没有接近能够删除 col b 中 col a 中的第二个(并且只有第二个)字符串。我想我问的是类似于this 的问题,但我不熟悉 Perl,无法将其翻译成 R。
谢谢!
【问题讨论】:
标签: r regex string find-occurrences