2017-06-21 98 views
0

我嘗試使用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 

你知道我有什麼關係?

回答

2

你需要從兩個dataframes你要反連接其列指定,所以你有這樣的事情

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

否則R不知道被加入的列。兩個數據幀都需要有一個共同的點,以加入任意連接函數

0

沒有其他參數,anti_join希望加入具有相同列名稱的數據幀。

訣竅是

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

或者像sweetmusicality解釋。

1

我有同樣的問題,但不是創建一個新的對象,而是使用管道運算符,並使用與stopword變量相同的名稱:「word」。 這種方式anti_join加入具有相同列名的數據幀

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