R语言文本分析
Posted 管理研究方法
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了R语言文本分析相关的知识,希望对你有一定的参考价值。
如果对实验研究感兴趣,欢迎阅读:;如果对问卷研究感兴趣,欢迎阅读:、、;如果对多层线性回归模型感兴趣,欢迎阅读:、、;如果对元分析感兴趣,欢迎阅读:、。
R code来源于政府报告词云图[1]
分析的网络文本来源于政府工作报告(文字实录)[2]
R语言分析如下:
library(jiebaR)
library(tidyverse)
library(rvest)
library(wordcloud2)
url <- "http://www.gov.cn/premier/2020-05/22/content_5513757.htm"
text <- url %>%
read_html(encoding="utf-8") %>%
html_nodes("div.pages_content") %>%
html_text()
stopwords_CN <- c("被","怎么","还是","多少","得", "吗","给",
"年","月","还","个","能", "日","什么","做","没","啊",
"的", "了", "在", "是", "我", "有", "和", "就","不",
"人", "都", "一", "一个", "上", "也", "很", "到", "说",
"要", "去", "你","会", "着", "没有", "看", "好",
"自己", "这", "等")
#初始化分词引擎
engine <- worker()
#开始分词
seg <- segment(text,engine)
tibble(seg) %>%
count(seg,sort=TRUE) %>%
filter(!seg %in% stopwords_CN) %>%
top_n(150) %>%
wordcloud2(size=1,shape="star")
生成的词云如下:
参考资料:
dragon25428的github仓库资料: https://github.com/dragon25428/R-Web-Crawler/blob/master/政府报告词云图.R
[2]政府工作报告(文字实录): http://www.gov.cn/premier/2020-05/22/content_5513757.htm
以上是关于R语言文本分析的主要内容,如果未能解决你的问题,请参考以下文章