R:在逆向中使用德语停用词,但防加入不起作用

问题描述:

我尝试使用tidyverse(http://tidyverse.org/)分析德语句子列表。我坚持这个指南(http://tidytextmining.com/)。R:在逆向中使用德语停用词,但防加入不起作用

当我尝试使用德语停用词表时,它不起作用。

library(tidyverse) 
library(readxl) # read excel 
library(tibble) # tobble dataframe 
library(dplyr) # piping 
library(stringr) # character manipulation 
library(tidytext) 
library(tokenizers) 

data <- read_xlsx("C:/R/npsfeedback.xlsx", sheet = "Tabelle1", col_names="feedback") 
data 
is.tibble(data) 

# tokenise 
data_clean <- data %>% 
    na.omit() %>% 
    unnest_tokens(word,feedback) 

这也部分造成我的麻烦:

# remove stopwords 
sw <- tibble(stopwords("de")) 
sw 

data_clean <- data_clean %>% 
    anti_join(.,sw) 

我topwords是与一列字符类型tibble。 但是,如果我尝试使用anti_join我得到这样的输出:

Error: `by` required, because the data sources have no common variables 

你知道我有什么关系?

你需要从两个dataframes你要反连接其列指定,所以你有这样的事情

antijoin(., sw, by = c("first_df_var" = "second_df_var")) 

否则R不知道被加入的列。两个数据帧都需要有一个共同的点,以加入任意连接函数

没有其他参数,anti_join希望加入具有相同列名称的数据帧。

诀窍是

sw <- tibble(word = stopwords("de")) 

或者像sweetmusicality解释。

我有同样的问题,但不是创建一个新的对象,而是使用管道运算符,并使用与stopword变量相同的名称:“word”。 这种方式anti_join加入具有相同列名的数据帧

`data_clean <- data %>% 
       mutate(linenumber = row_number()) %>% 
       unnest_tokens(word, feedback) %>% 
       anti_join(get_stopwords(language = "de")) %>% 
       ungroup()`