【问题标题】:Index of word within text in RR中文本中单词的索引
【发布时间】:2014-02-06 12:40:22
【问题描述】:

我在字符向量中有文本,但我无法在字符向量中找到单词的索引,如何在不遍历每个单词并使用 nchar 和添加每个单词的长度的情况下有效地提取它匹配

which("ashish"=="i am ashish and ashish is good")
integer(0)
grep("apple","i am ashish and ashish is good")
integer(0)
grep("apple","It is a apple and apple is tasty")
[1] 1

我想要文本中 9,19 的“apple”索引。任何关于更好方法的建议,谢谢。

【问题讨论】:

    标签: r text vector indexing


    【解决方案1】:

    gregexp 是您要查找的函数:

    gregexpr("apple","It is a apple and apple is tasty")
    

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 2021-10-25
      • 1970-01-01
      • 2020-11-06
      • 2023-03-26
      • 2019-02-08
      • 1970-01-01
      • 2013-07-05
      • 2014-12-30
      相关资源
      最近更新 更多