Kmeans聚类和文本挖掘在R
问题描述:
我有一个包含twitter数据(只有1个文件)的txt文件。我使用streamR和parseTweets函数将它加载到R中。我需要对这些数据进行Kmeans聚类。首先,我需要清理和准备数据,但数据是数字的混合体,它不允许我这样做:(例如)内容转换。
如何摆脱这些数据中所有不需要的字符?我只需要纯文本。无数字,特殊字符等Kmeans聚类和文本挖掘在R
*library(streamR)
install.packages("RCurl")
install.packages("bitops")
install.packages("rjson")
library(bitops)
library(RCurl)
library(rjson)
library(NLP)
library(tm)
library(SnowballC)
library(XML)
tweets.df<-parseTweets('tweetsStream.txt', simplify = FALSE);
tweets.df<-tm_map(tweets.df,content_transformer(tolower));
Error in UseMethod("tm_map", x) :
no applicable method for 'tm_map' applied to an object of class "data.frame"*
答
tm_map函数将语料作为输入数据类型取回。试试这个:
docs <- Corpus(DirSource(cname))
docs <- tm_map(docs, tolower)
这里找到完整的例子:https://rstudio-pubs-static.s3.amazonaws.com/31867_8236987cf0a8444e962ccd2aec46d9c3.html
进一步的细节,你总是可以运行
??tm_map
或??tm
去你的[R控制台整个文档。
Regards, Markus