代码之家  ›  专栏  ›  技术社区  ›  Doug Fir

使用qdap的dplyr过滤器::哪个错误或dplyr滤波器带有嵌套函数

  •  1
  • Doug Fir  · 技术社区  · 9 年前

    小数据帧:

    words <- data.frame(terms = c("qhick brown fox",
              "tom dick harry", 
              "cats dgs"))
    

    如果我使用 qdap::which_misspelled 我可以找出拼写错误的单词:

    > which_misspelled(words)
          1       8 
    "qhick"   "dgs" 
    

    如何根据包含拼写错误单词的任何行来子集df?

    (如果可以使用dplyr过滤器,则会获得额外奖励)

    1 回复  |  直到 9 年前
        1
  •  4
  •   akuiper    9 年前

    直接使用怎么样 check_spelling 它是矢量化的,结果包含一列行号,您可以使用这些行号来子集数据帧:

    library(qdap)
    words[check_spelling(words$terms)$row,,drop=F]
    
    #            terms
    #1 qhick brown fox
    #3        cats dgs
    

    which_misspelled

    which_拼写错误-检查字符串的拼写。