Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R &引用;匹配错误(x,表格,nomatch=0L):&x27;匹配';需要向量参数“;_R_Match_Stop Words - Fatal编程技术网

R &引用;匹配错误(x,表格,nomatch=0L):&x27;匹配';需要向量参数“;

R &引用;匹配错误(x,表格,nomatch=0L):&x27;匹配';需要向量参数“;,r,match,stop-words,R,Match,Stop Words,我使用这个代码块来获取训练数据集中的单词数,并根据找到它的文章编号对其进行索引。 这是我正在使用的数据框架,一旦代码运行,文档列中的每个单词都将被放在自己的单元格中,并索引到它来自哪个文档(最左边的列中的数字) dput(droplevels(head(TrainData))) structure(list(Class = c("atheism", "atheism", "atheism", "atheism", "atheism", "atheism"), Document = c(" at

我使用这个代码块来获取训练数据集中的单词数,并根据找到它的文章编号对其进行索引。 这是我正在使用的数据框架,一旦代码运行,文档列中的每个单词都将被放在自己的单元格中,并索引到它来自哪个文档(最左边的列中的数字)

dput(droplevels(head(TrainData)))
structure(list(Class = c("atheism", "atheism", "atheism", "atheism", 
"atheism", "atheism"), Document = c(" atheism faq atheist resources ", 
" atheism faq introduction to atheism archive name atheism introduction ",
"gospel dating in article mimsy umd edu mangoe cs umd edu charley ", 
"university violating separation of church state dmn kepler unh edu ",  
"soc motss et al princeton axes matching funds for boy scouts in article ",   
"a visit from the jehovah s witnesses in article apr batman bmd trw com"  
), Index = 1:6), row.names = c(NA, 6L), class = "data.frame")
用于分隔每个单词并对其进行索引的代码块是:

library(tidytext) 
TrainData$Index = 1:dim(TrainData)[1]  # provides an index of what articles are connected with each word
TrainData_words <- TrainData %>%     # add the original row numbers as index
  unnest_tokens(word,Document) %>%
  filter(str_detect(word, "[a-z']$"),
     !word %in% stop_words$word)   # removing the stop-words (actual words that do not impact text mining or correlation)
我已经通读了关于这个特定错误消息的帖子,a=但仍然无法确定哪些内容可能发生了更改或遗漏?
提前谢谢大家。

您能提供一些数据让您的示例重现吗?比如
dput(head(TrainData))
可能很好。独立索引属于前一行的注释,现在已修复。我尝试放置我正在使用的数据帧的一个外观,我希望它能正常运行。它有四列,从L-R开始:行编号(文档编号),类,文档,索引。谢谢。Gregor,你的帮助和支持令人难以置信,我很感激!我将尝试你提供的新代码,看看我能做些什么…请继续关注!谢谢。希望新的数据帧示例格式能起作用。@Shawn hi Shawn,在我遇到同样的错误后看到了这篇文章。虽然我无法准确地知道是什么这是导致错误的原因,我可以让我的代码再次工作。尝试在筛选器调用中的第二个布尔语句周围添加括号,以分隔否定感叹号。因此
filter(stru detect(word,[a-z']$),!word%in%stop\u words$word)
将变成
filter(str\u detect(word,[a-z']$)!(单词%in%stop\u words$word))
你能提供一些数据让你的例子重现吗?比如
dput(head(TrainData))
可能很好。独立索引属于前一行的注释,现在已修复。我尝试放置我正在使用的数据帧的一个外观,我希望它能正常运行。它有四列,从L-R开始:行编号(文档编号),类,文档,索引。谢谢。Gregor,你的帮助和支持令人难以置信,我很感激!我将尝试你提供的新代码,看看我能做些什么…请继续关注!谢谢。希望新的数据帧示例格式能起作用。@Shawn hi Shawn,在我遇到同样的错误后看到了这篇文章。虽然我无法准确地知道是什么这是导致错误的原因,我可以让我的代码再次工作。尝试在筛选器调用中的第二个布尔语句周围添加括号,以分隔否定感叹号。因此
filter(stru detect(word,[a-z']$),!word%in%stop\u words$word)
将变成
filter(str\u detect(word,[a-z']$)!(单词%in%stop\u words$word))
> traceback()
12: word %in% stop_words$word
11: match.arg(method)
10: filter(., str_detect(word, "[a-z']$"), !word %in% stop_words$word)
9: filter(., str_detect(word, "[a-z']$"), !word %in% stop_words$word)
8: function_list[[k]](value)
7: withVisible(function_list[[k]](value))
6: freduce(value, `_function_list`)
5: `_fseq`(`_lhs`)
4: eval(quote(`_fseq`(`_lhs`)), env, env)
3: eval(quote(`_fseq`(`_lhs`)), env, env)
2: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1: TrainData %>% unnest_tokens(word, Document) %>% filter(str_detect(word, 
       "[a-z']$"), !word %in% stop_words$word)