【发布时间】:2019-01-07 17:01:55
【问题描述】:
这里是示例数据:
example_sentences <- data.frame(doc_id = c(1,2,3),
sentence_id = c(1,2,3),
sentence = c("problem not fixed","i like your service and would tell others","peope are nice however the product is rubbish"))
matching_df <- data.frame(x = c("not","and","however"))
由reprex package (v0.2.1) 于 2019-01-07 创建
我想在字符串中的某个word 之前添加/插入逗号。例如,如果我的字符串是:
problem not fixed.
我想把它转换成
problem, not fixed.
另一个matching_df 包含要匹配的单词(这些是Coordinate conjunctions),因此如果在matching_df 中找到x,则在detected word 之前插入comma + space。
我查看了stringr 包,但不知道如何实现。
最好的,
【问题讨论】:
-
@MrFlick 我使用 reprex 示例进行了编辑