使用tidytext,我有以下代码:
data(stop_words)
tidy_documents <- tidy_documents %>%
anti_join(stop_words)我希望它使用内置到包中的停止字,将名为tidy_documents的数据帧写入同名的数据帧,但如果它们在stop_words中,则删除这些字。
我得到了这个错误:
错误:没有公共变量。请指定by参数。回溯:
1. tidy_documents %>% anti_join(stop_words)
2. withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
3. eval(quote(`_fseq`(`_lhs`)), env, env)
4. eval(expr, envir, enclos)
5. `_fseq`(`_lhs`)
6. freduce(value, `_function_list`)
7. withVisible(function_list[[k]](value))
8. function_list[[k]](value)
9. anti_join(., stop_words)
10. anti_join.tbl_df(., stop_words)
11. common_by(by, x, y)
12. stop("No common variables. Please specify `by` param.", call. = FALSE)发布于 2017-05-15 06:24:59
tidy_document和stop_words都在名为word的列下列出了单词列表;但是,这两列是颠倒的:在stop_words中,它是第一列,而在您的数据集中,它是第二列。这就是为什么该命令无法“匹配”这两列并比较单词的原因。试试这个:
tidy_document <- tidy_document %>%
anti_join(stop_words, by = c("word" = "word"))by命令强制脚本比较称为word的列,而不管它们的位置。
发布于 2017-10-19 08:09:59
您可以使用更简单的filter()来避免使用令人困惑的anti_join()函数,如下所示:
tidy_documents <- tidy_documents %>%
filter(!word %in% stop_words$word)https://stackoverflow.com/questions/43441884
复制相似问题