【发布时间】:2021-11-05 22:11:36
【问题描述】:
所以我有这个带有标记的大量 tibble,我正在尝试对其进行一些过滤,然后转换为文档术语矩阵。
我的问题是分组过滤过程运行得很慢。
是否有人对我如何加快处理速度或删除出现在多于/少于 n% 的文档中的单词有什么好的建议? (我不喜欢TM包,我是初学者)。
代码:
dtm <-
token %>%
count(document,word) %>%
filter(nchar(word)>2,
nchar(word)<30) %>% #Keep words with 2-30 characters
group_by(word) %>%
filter((n()/length(unique(dtm$document))) < 0.8, # Remove words that occurs in more <br>than n% documents
(n()/length(unique(dtm$document))) > 0.00001) %>% # Remove words that occurs in <br>less than n% documents
tidytext::cast_dtm(document = document, term = word, value = n)
【问题讨论】: