writeLines()在transformation-r tm包之后返回blank.txt
我正在创建语料库,并使用writeLines()在transformation-r tm包之后返回blank.txt,r,tm,R,Tm,我正在创建语料库,并使用tm包转换一堆.txt文件。这些.txt文件包含我从网页复制和粘贴的文本。运行语料库代码后,我运行了writeLines(as.character)函数来检查文件。但是,返回的三个.txt文件为空 然后,在我将大小写和标点符号转换如下后,更多的文件返回为空白 docs <- Corpus(DirSource(...)) docs <-tm_map(docs,content_transformer(tolower)) toSpace <- content_
tm
包转换一堆.txt
文件。这些.txt
文件包含我从网页复制和粘贴的文本。运行语料库代码后,我运行了writeLines(as.character)
函数来检查文件。但是,返回的三个.txt
文件为空
然后,在我将大小写和标点符号转换如下后,更多的文件返回为空白
docs <- Corpus(DirSource(...))
docs <-tm_map(docs,content_transformer(tolower))
toSpace <- content_transformer(function(x, pattern) { return (gsub(pattern, " ", x))})
docs <- tm_map(docs, toSpace, ":")
docs <- tm_map(docs, toSpace, "–")
docs <- tm_map(docs, toSpace, "’")
docs <- tm_map(docs, toSpace, "'")
docs <- tm_map(docs, toSpace, ".")
docs <- tm_map(docs, toSpace, "“")
docs <- tm_map(docs, toSpace, "”")
writeLines(as.character(docs[[10]]))
docsgsub
使用regex,因此gsub(“.”,“”,x)
将用空格替换每个字符。您需要将其删除:gsub(“\\.”,“,”,x)
谢谢您的回复。我把“.”的代码改成了“\\”,它成功了!