【发布时间】:2021-11-29 20:25:20
【问题描述】:
我正在使用此解决方案 (get what percent of documents contain a feature - quanteda) 来查找包含我的数据集中任何一组特征的文档的数量。只要文档包含任何一个单词,我希望它返回 TRUE。
我让它工作了,但它只在某些时候工作,我不知道为什么。删除或添加单词有时有效,有时无效。这是我使用的代码(复合短语在dfm中已经是“tokens_compound”)
thetarget <- c("testing", "test", "example words", "example")
df <- data.frame(docname = docnames(dfm),
Year = docvars(dfm, c("Year")),
contains_target = rowSums(dfm[, thetarget]) > 0,
row.names = NULL)
我有时会遇到的错误
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'rowSums':
Subscript out of bounds
TIA
编辑(创建表格的脚本,显示包含任何目标词的年份和文档数量):
df2 <- df %>%
mutate_if(is.logical, as.character) %>%
filter(!str_detect(contains_target, "FALSE")) %>%
group_by(Year) %>%
summarise(n = n())
【问题讨论】:
-
问题是当
dfm[, thetarget]没有定义时;我不明白你正在使用的软件包,但这有帮助吗?
标签: r error-handling nlp quanteda