r - 知道两个dfm之间哪些单词不同的代码是什么?
问题描述
我有两个 dfm,我想知道它们之间缺少哪些单词/不同。例如,
library(quanteda)
df1 <- data.frame(Text = c("Stackoverflow is a great place where very skilled data scientists are willing to help you. Trust me you will need help if you are doing a PhD. So Stack is immensely useful. Thank you guys to sort this out for me."), stringsAsFactors = F)
corpus1 <- corpus(df1, text_field = "Text")
df2 <- data.frame(Text = c("Stackoverflow is a great place where very skilled data scientists are willing to help you. Trust me you will need help if you are doing a PhD."), stringsAsFactors = F)
corpus2 <- corpus(df2, text_field = "Text")
dfm1 <- dfm(corpus1, remove_punct = TRUE)
dfm2 <- dfm(corpus2, remove_punct = TRUE)
我想看看 dfm2 中的哪些单词不在 dfm1 中。非常感谢你的帮助!
解决方案
上面的答案效果很好。但是,我认为可以使用以下方法更清洁dfm_select
:
dfm_select(dfm1, pattern = dfm2, selection = "remove")
#> Document-feature matrix of: 1 document, 10 features (0.0% sparse).
#> 1 x 10 sparse Matrix of class "dfm"
#> features
#> docs so stack immensely useful thank guys sort this out for
#> text1 1 1 1 1 1 1 1 1 1 1
推荐阅读
- javascript - Vue.js @click 在移动设备上的选项中不起作用
- javascript - 图表上的 amcharts (v3.x) 日期格式问题
- kubernetes - 出口 IP 地址选择
- html - 为每个图像应用一个固定的 px 单位
- android - Android中没有数组名称或节点的JSON解析
- mysql - 查找并行时间的动作记录
- laravel - Laravel - 路由(“resource.destroy”)调用“resource.show”
- python - 正则表达式:使用 re.sub 删除重复空格在所有字符后返回逗号
- php - 尝试将数组插入数据库而不重复
- c# - Binance API 调用在控制台应用程序上运行良好,但在 WinForm c# 上运行良好