r - Why can't R read the text file
问题描述
Try to get R read my text file and do a text mining, but following the steps it's not working, don't know what's wrong. Someone plz help me
library(tm)
setwd("E://")
path="E:/KEYWORDS"
text<-readLines("KEYWORDS.txt")
corpus<- Corpus(VectorSource(text))
corpus<- tm_map(corpus,tolower)
corpus<- tm_map(corpus,removePunctuation)
corpus<-tm_map(corpus,stripWhitespace)
corpus<-Corpus(VectorSource(corpus))
tdm =TermDocumentMatrix(corpus,PlainTextDocument)
findFreTerms(tdm,lowfreq=2)
And it shows:
Warning message:
In tm_map.SimpleCorpus(corpus, removePunctuation) :
transformation drops documents
tdm =TermDocumentMatrix(corpus,PlainTextDocument)
Error: is.list(control) is not TRUE
And if you do this
str(readLines("KEYWORDS.txt"))
paste(str(readLines("KEYWORDS.txt")),collapse=" ")
text<-paste(str(readLines("KEYWORDS.txt")),collapse=" ")
gsub(pattern="//W", replace=" ", text)
text<-gsub(pattern="//W",replace=" ",text)
gsub(pattern="//d", replace=" ", text)
text<-gsub(pattern="//d", replace=" ", text1)
tolower(text)
text<-tolower(text)
text
It shows the text is null or contains 0 characters why?
解决方案
tdm =TermDocumentMatrix(corpus,PlainTextDocument)
Error: is.list(control) is not TRUE
that's because you've given the second parameter to TermDocumentMatrix
as PlainTextDocument
rather than a list of control arguments. Read the documentation for TermDocumentMatrix to see what is a valid set of control arguments.
You say you are doing this by "following the steps" but you should understand the steps first.
推荐阅读
- c# - 无法在 UWP 中使用 FromFile 中的路径加载图像
- mysql - 如何导出从 mysql 查询返回的“结果”?
- oracle - Oracle UTL_FILE 读取 CSV 文件行
- database - 在具有简单桌面 c# 应用程序的单台机器上运行时,如何管理(init\start\restart\create schema)我的 postgreSQL 服务器?
- wordpress - 如何在不影响主题或网站其他部分的情况下将自定义 HTML 文件插入 WordPress
- c++ - 异常后重置 Cuda 上下文
- javafx - 如何从子控制器为父控制器中的元素设置 FXML 属性
- amazon-cloudformation - 在 userdata 脚本中使用 boto3 时出现 MissingServiceIdError
- laravel - Laravel 错误 - 调用未定义的方法 Illuminate\Database\Query\Builder::gets()
- java - Java File.setReadable() 在 Windows 上不起作用