问题描述
我想使用 tidytext 包中的函数 unnest_tokens 进行二元分析。几周前它有效,但现在我的输出只有 NA。
我有以下 df str(df)
:
'data.frame': 36199 obs。共 1 个变量: $ words: 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,这篇文章有帮助:Opposite of unnest_tokens 使用以下代码 text.ngram<-df%>% group_by(mygroupingvariable) %>% summarize(text = str_c(words,collapse = " ")) %>% ungroup()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)