【发布时间】:2016-06-15 09:11:01
【问题描述】:
我在下面的句子中找出了“oo”的位置:
sentence <- "It is a good book. Good for first reading.
This book explains everything in Qdetail with tons of examples and exercises for practice. Good for cracking written tests on campuses and competitive exams. It is cheap so any way one can have a copy along with other books"
pos = gregexpr("oo", sentence)
我得到的结果是
> pos
[[1]]
[1] 10 15 21 50 136 263
attr(,"match.length")
[1] 2 2 2 2 2 2
attr(,"useBytes")
[1] TRUE
根据结果,我想从每个位置提取10个字符(位置前5个,位置后5个)
例如, 我应该得到第一个位置的结果 “是个好人” 我希望对每个职位都进行这种提取。 由于我是 R 新手,所以我不知道该怎么做。 这个你能帮我吗。
如果我必须提取如下所示的单词,我该怎么办: 我应该为第一个匹配实例获得“一本好书”
【问题讨论】: