R语言-文本挖掘例子

以总理2015报告原文进行挖掘处理,先将报告内容保存为TXT格式文本。

需要的包:rJava,Rwordseg,wordcloud。

library(rJava)

library(Rwordseg)

library(wordcloud)

1、读入文本数据

mydata<-read.csv("D:/test/R/report2015.txt", stringsAsFactors=FALSE,header=FALSE)

2、中文分词

txt<-segmentCN(as.character(mydata$V1))

3、将列表转换为向量

txt.aslist<-unlist(txt)

4、词语统计

txt.freq<-table(txt.aslist)

5、频数排序

txt.result<-txt.freq[order(-txt.freq)]

6、画词云

wordcloud(names(txt.result),txt.result,random.order=FALSE)

7、取前100位画词云

 wordcloud(names(text.result)[1:100],text.result[1:100],random.order=FALSE)


如果要去除停止词,可使用下面的步骤:

8、使用去停止词

(1)导入停止词表

stopword<-read.csv('D:/test/R/stop-word.txt',stringsAsFactors=FALSE,header=FALSE)

(2)将data.frame类型数据转换为向量型数据

stopword.v<-as.vector(stopword$V1)

(3)去除词语统计中的停止词

word.pure<-setdiff(names(txt.result),stopword.v)

word.pure为去除停止词的统计分析对象词表。

(4)取出非停止词

txt.pure<-txt.result[word.pure]

(5)画词云

wordcloud(names(txt.pure)[1:100],txt.pure[1:100],random.order=FALSE)




注意:

对table对象 ta,

dimnames(ta) 结果为list型

names(ta)结果为向量型。

With more than 200 practical recipes, this book helps you perform data analysis with R quickly and efficiently. The R language provides everything you need to do statistical work, but its structure can be difficult to master. This collection of concise, task-oriented recipes makes you productive with R immediately, with solutions ranging from basic tasks to input and output, general statistics, graphics, and linear regression. Each recipe addresses a specific problem, with a discussion that explains the solution and offers insight into how it works. If you're a beginner, R Cookbook will help get you started. If you're an experienced data programmer, it will jog your memory and expand your horizons. You'll get the job done faster and learn more about R in the process. * Create vectors, handle variables, and perform other basic functions * Input and output data * Tackle data structures such as matrices, lists, factors, and data frames * Work with probability, probability distributions, and random variables * Calculate statistics and confidence intervals, and perform statistical tests * Create a variety of graphic displays * Build statistical models with linear regressions and analysis of variance (ANOVA) * Explore advanced statistical techniques, such as finding clusters in your data "Wonderfully readable, R Cookbook serves not only as a solutions manual of sorts, but as a truly enjoyable way to explore the R language-one practical example at a time." -Jeffrey Ryan, software consultant and R package author
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值