nchar(Terms(x), type = "chars") 中的错误:检查文档术语矩阵时,多字节字符串无效,元素 204 [英] Error in nchar(Terms(x), type = "chars") : invalid multibyte string, element 204, when inspecting document term matrix
本文介绍了nchar(Terms(x), type = "chars") 中的错误:检查文档术语矩阵时,多字节字符串无效,元素 204的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我使用过的源代码:
Here is the source code that I have used:
MyData <- Corpus(DirSource("F:/Data/CSV/Data"),readerControl = list(reader=readPlain,language="cn"))
SegmentedData <- lapply(MyData, function(x) unlist(segmentCN(x)))
temp <- Corpus(DataframeSource(SegmentedData), readerControl = list(reader=readPlain, language="cn"))
预处理数据
temp <- tm_map(temp, removePunctuation)
temp <- tm_map(temp,removeNumbers)
removeURL <- function(x)gsub("http[[:alnum:]]*"," ",x)
temp <- tm_map(temp, removeURL)
temp <- tm_map(temp,stripWhitespace)
dtmxi <- DocumentTermMatrix(temp)
dtmxi <- removeSparseTerms(dtmxi,0.83)
**inspect(t(dtmxi))** ---This is where I get the error
推荐答案
我的RStudio
在设置Sys.setlocale('LC_ALL','C')
并运行 TermDocumentMatrix( mycorpus )
函数.
My RStudio
restarts the session after to set Sys.setlocale( 'LC_ALL','C' )
and run the TermDocumentMatrix( mycorpus )
function.
这篇关于nchar(Terms(x), type = "chars") 中的错误:检查文档术语矩阵时,多字节字符串无效,元素 204的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文