我是R的新手,最近开始研究文本分析项目。我试图用一个词汇来构成我的故事。 我安装的软件包是:
tm
SnowballC
wordcloud
数据是反馈的数据,包含很多用于生成票证的垃圾词,这些词不是英语的一部分。 有没有办法删除垃圾词,只在那些适当的英语? 我试图列出要删除的单词列表,但列表中有太多要添加的内容。
请帮忙...... 感谢
答案 0 :(得分:0)
要删除停用词,请尝试以下操作:
df %>%
unnest_tokens(word_column, text_column) %>%
anti_join(stop_words, by = "word_column")
我不知道你是否已经将文本分成单个单词,因此有功能不需要的标记(输出列名,输入列名(带有句子的列))。
反连接功能将删除停用词
答案 1 :(得分:0)
要删除非英语单词,请使用数据框内联接您的数据" parts_of_speech
"从tidytext
包中删除停用词,使用相同tidytext包中的数据框。
library(dplyr) # loads inner_join, anti_join
# load unnest_tokens(); parts_of_speech stop_words data frames:
library(tidytext)
data(package="tidytext") # show built-in data frames
# optional, show richness of parts_of_speech dataset
all_english_words <- parts_of_speech$word # , > 200000 rows
grep("apple", all_english_words, value=TRUE)
# assume data-frame df containing your data was already created,
# contains column `text_column`, all lowercase
new_df <- df %>%
unnest_tokens(word, text_column) %>%
inner_join(word, parts_of_speech, by = "word") %>%
anti_join(stop_words, by = "word")
glimpse(new_df)
可能需要一些微调。