如何从tm包中的findAssocs函数返回的结果中删除非关联的单词

时间:2017-03-09 19:57:06

标签: r tm

我正在使用R中tm包中的findAssocs函数来查找与给定单词集相关联的所有单词。返回的结果显示一些与任何单词无关的单词。例如,在下面的输出中,单词“new”与最小相关系数为0.7的任何单词都没有关联。所以我想删除所有这些单词并创建一个具有一些关联的单词向量。在这种情况下,向量将是c("blush")。那我该怎么做呢?  感谢

> findAssocs(myTdm,c("new","blush"),0.7)
$new
numeric(0)

$blush
  combination     customize     different       endless         flush     highlight        jdlxmd        master 
         0.98          0.98          0.98          0.98          0.98          0.98          0.98          0.98 
possibilities         three        unique           use 
         0.98          0.98          0.98          0.98  

1 个答案:

答案 0 :(得分:1)

您可以使用功能<div class='wrapper'> <div class='container'> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin hendrerit nulla id odio tincidunt, in rutrum diam dapibus. Mauris et urna luctus turpis sollicitudin dictum venenatis eget massa. Suspendisse maximus lectus in nunc placerat, nec interdum massa iaculis. Nullam sit amet ex feugiat, cursus enim non, viverra lectus. Curabitur blandit risus sed dolor viverra, sit amet auctor metus ornare. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus placerat sollicitudin ligula, convallis mattis leo porttitor vitae. Praesent id metus id erat condimentum porta. Phasellus a sapien vel lacus imperdiet pellentesque sed at risus. Curabitur venenatis scelerisque augue, quis congue lorem feugiat eu. Suspendisse placerat elit non augue suscipit pretium. </p> <br> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin hendrerit nulla id odio tincidunt, in rutrum diam dapibus. Mauris et urna luctus turpis sollicitudin dictum venenatis eget massa. Suspendisse maximus lectus in nunc placerat, nec interdum massa iaculis. Nullam sit amet ex feugiat, cursus enim non, viverra lectus. Curabitur blandit risus sed dolor viverra, sit amet auctor metus ornare. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus placerat sollicitudin ligula, convallis mattis leo porttitor vitae. Praesent id metus id erat condimentum porta. Phasellus a sapien vel lacus imperdiet pellentesque sed at risus. Curabitur venenatis scelerisque augue, quis congue lorem feugiat eu. Suspendisse placerat elit non augue suscipit pretium. </p> </div> </div>compact中的purrr

lengths
在基数R中

,您还可以将findAssocsRes <-list(a=integer(0),b=c(x=1,y=2) ,c=c(z=1) ) findAssocsRes $a integer(0) $b x y 1 2 $c z 1 purrr::compact(findAssocsRes,lengths) $b x y 1 2 $c z 1 lapply

一起使用
length