r - R中的Wordcloud包括字符“和”,我该如何删除它们?
问题描述
我试图从福尔摩斯的故事中制作一个词云,问题是最重要的词是“和”。
我不能用带有属性的tm_map
函数来删除它们。removeWords
我试过的是这样的:
docs <- tm_map(docs, removeWords, c('“'))
解决方案
您可以使用removePunctuation
包中的功能tm
。
library(tm)
library(janeaustenr)
# With Punctuation
data("prideprejudice")
prideprejudice[30]
# Punctuation Removed
prideprejudice <- removePunctuation(prideprejudice)
prideprejudice[30]
您也可以使用该tidytext
软件包。该unnest_tokens
功能将自动去除标点符号。您可能还想摆脱停用词,您可以这样做:
library(tm)
library(tidytext)
library(janeaustenr)
library(dplyr)
data("prideprejudice")
data(stop_words)
prideprej_tibble <- tibble(text=prideprejudice)
prideprej_words <- prideprej_tibble %>%
unnest_tokens(word, text) %>%
anti_join(stop_words)
请参阅此处了解更多信息。
推荐阅读
- c# - C# - 运行顺序任务的正确方法?
- php - 路线存在时找不到Laravel路线
- angularjs - 解码返回“错误:URI 太长”的 AngularJS URL
- haskell - 创建一个函数,计算出现在列表列表中的所有不同单词的计数
- shared-libraries - 如何识别共享库中定义的数组?
- swiftui - SwiftUI 中的小弹出协议窗口
- yii2 - api.suite.yml Yii2 codeception 配置文件的内容应该如何?
- python - 仅当第一个函数首先使用 Multiprocessing 运行时才一起运行两个函数
- charts - 谷歌图表:自定义刻度
- javascript - 我如何将画布内容作为文件放入输入类型文件中