没有适用于&#t; tm_map'的方法适用于类"字符"的对象

时间:2017-08-04 19:48:28

标签: r matrix text-mining tm

我的数据如下:

1. Good quality, love the taste, the only ramen noodles we buy but they're available at the local Korean grocery store for a bit less so no need to buy on Amazon really.
2. Great flavor and taste. Prompt delivery.We will reorder this and other products from  this manufacturer.
3. Doesn't taste good to me.
4. Most delicious ramen I have ever had. Spicy and tasty. Great price too.
5. I have this on my subscription, my family loves this version. The taste is great by itself or when we add the vegetables and.or meats.
6. The noodle is ok, but I had better ones.
7. some day's this is lunch and or dinner  on second case
8. Really good ramen!

(skip)

我整理了这些数据(数字消除,小写转换,删除特殊字符)

我想创建一个矩阵和sna图。

但是,数据清理过程存在问题。

Error in UseMethod("tm_map", x) : 
  no applicable method for 'tm_map' applied to an object of class "character"   

我该怎么办?

docs<- readLines("C:/Users/xxx/Desktop/3694.txt", encoding = "UTF-8")

library(tm)
docs <- tm_map(docs,removePunctuation)     
docs <- tm_map(docs, tolower)   
docs <- tm_map(docs, PlainTextDocument)
DocsCopy <- docs

1 个答案:

答案 0 :(得分:-1)

干净<-函数(x){

x <-tolower(x)

x <-removeWords(x,停用词('en'))

x <-removePunctuation(x)

x <-stripWhitespace(x)

返回(x) }