r - R tidytext 包函数 unnest_tokens 的问题
问题描述
我想使用 tidytext 包中的函数 unnest_tokens 进行二元分析。它在几周前工作,但现在我的输出只是 NA。
我有以下 df str(df)
:
'data.frame':36199 obs。1 个变量:$ 单词:chr "jed" "tag" "neu" "verunsichern" ...
当我使用以下代码进行二元分析时,bigrams <- df %>% unnest_tokens_(bigram, words, token = "ngrams", n = 2)
我的输出只有 NA:
head(bigrams)
: | | 二元组 | | -------- | -------------- | | 1.内容| 不适用 | | 2.内容| 不适用 |
我需要先使用 tm_map 函数清理加载的文本,然后按如下方式创建 df:
df0 <- data.frame(text=unlist(sapply(myVCorpus,
[, "content")), stringsAsFactors=F)
和df<- df0 %>% unnest_tokens(words, text)
. 我更新了最新的 R 并更新了我的包。我真的不知道,为什么它停止工作。
预先感谢您的意见。亲切的问候克里斯托夫
更新:它必须与准备好的df有关。如果我使用 df,在我清理它之前整个句子都在一个单元格中,它可以工作。这就是我清理文本的过程:
df<- %>% unnest_tokens(word, text)
myVCorpus <- VCorpus(VectorSource(df))
myVCorpus <- tm_map(text.prep, removeWords, stopwords(kind= "de"))
更新2:我找到了解决方案。我需要整理准备好的df,这篇文章有帮助:unnest_tokens的对面,代码如下text.ngram<-df%>% group_by(mygroupingvariable) %>% summarize(text = str_c(words, collapse = " ")) %>% ungroup()
解决方案
推荐阅读
- syncfusion - 如何将 Syncfusion Vue 示例与 Stack blitz 一起使用
- azure-webjobs - 将小批量数据摄取到 azure 数据资源管理器时避免 webjob 等待
- python - 线程仅在睡眠时共享 cpu
- step - 为什么我的 STEP 文件会导致分段错误?
- python - Matplotlib DateFormatter 行为变化:无法同时绘制主要和次要刻度标签
- python - 可以使用 pypy3 安装所有/大多数 python pip 包吗?
- tensorflow - 如何编写从输入层获取调整大小值的自定义调整大小层?
- python-3.x - 用行的频繁值替换行的所有值
- javascript - “未定义为频道聊天中的输出
- javascript - 如何使用角度 7 中 json 的真值和假值来选中和取消选中复选框