2017-10-24 2 views
0

텍스트 분석을 사용하고 있습니다. 나는 문장을 세어야했다. 내 코드 :R - 데이터 프레임에서 단어를 삭제하면 삭제됩니다.

library(dplyr) 
library(tidytext) 
txt <- readLines("consolidado.txt",encoding="UTF-8") 
txt = iconv(txt, to="ASCII//TRANSLIT") 
text_df <- data_frame(line = 1:392, text = txt) 
palabras1 <- text_df %>% unnest_tokens(bigram, text, token = "ngrams", n = 1) 
palabras2 <- text_df %>% unnest_tokens(bigram, text, token = "ngrams", n = 2) 
palabras3 <- text_df %>% unnest_tokens(bigram, text, token = "ngrams", n = 3) 
palabras4 <- text_df %>% unnest_tokens(bigram, text, token = "ngrams", n = 4) 
palabras5 <- text_df %>% unnest_tokens(bigram, text, token = "ngrams", n = 5) 
palabras6 <- text_df %>% unnest_tokens(bigram, text, token = "ngrams", n = 6) 
palabras7 <- text_df %>% unnest_tokens(bigram, text, token = "ngrams", n = 7) 

먼저 데이터 프레임에서 txt를 변환하고 나중에 tidytext로 작업합니다. 이 작업은 좋지만 문제는 중지 단어입니다. 나는 데이터 프레임에서 멈춤 단어를 삭제하고 싶지만 방법은 모른다. 나는 그것을 코퍼스에서 변환하려고 시도했으나 나중에는 단어를 멈추지는 않지만 문장을 세지 못하기 때문에이 방법으로는 작동하지 않습니다.

데이터 프레임에서 정지 단어를 삭제할 수있는 방법이 있습니까 ???

일반적인 중지 단어를 제거하기위한 표준화 된 기능을 포함 R 당신에게

+0

''stop_words '로'anti_join'을하십시오 – akrun

답변

1
내가 anti_join으로 시도

을 ...하지만 난이 오류를 얻을 :

by required, because the data sources have no common variables 

난과 노력이 문제에 대해 인터넷 검색 :

by = NULL 
by = c("a" = "b") 
by = c(namecolumn = namecolumn) 

을 "by"를 사용하면 여러 가지 방법을 사용할 수 있습니다. 그러나 나는 그것을 얻지 못했습니다.

마지막으로 나는이 솔루션을 가지고 :

library(tm) 
library(dplyr) 
library(tidytext) 

txt <- readLines("consolidado.txt",encoding="UTF-8") 
txt = iconv(txt, to="ASCII//TRANSLIT") 
text_df <- data_frame(line = 1:392, text = txt) 

text_df$text = removeWords(text_df$text, stopwords("spanish")) 
text_df$text = stripWhitespace(text_df$text) 

라이브러리 (Tm)가 스페인 중지 단어가 있습니다.

내 데이터 프레임에 텍스트가있는 열을 선택합니다. 기본적으로이 열을 텍스트라고합니다. 나중에 removeWords 함수를 사용하여 불용어를 지 웁니다. 마지막 줄은 중지 단어를 삭제 한 후에 이중 공백을 삭제하는 것입니다.

도움 주셔서 감사합니다.

1

대부분의 텍스트 마이닝 패키지 감사합니다. tidytext 패키지에서 저자는 공통 중지 단어가 포함 된 stop_words 데이터 세트를 포함합니다. 이런 식으로 뭔가 트릭 수행해야합니다

text_df <- data_frame(line = 1:392, text = txt) %>% 
         txt_df %>% 
         anti_join(stop_words) 
+0

스페인어 중지 단어를 사용할 수 있습니까 ??? – Alejo

관련 문제