问题
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"))
Preprocessing Data
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
回答1:
I believe there are some Chinese characters in your file. To overcome this issue, use this line of code to read them as well:
Sys.setlocale('LC_ALL','C')
回答2:
My RStudio
restarts the session after to set Sys.setlocale( 'LC_ALL','C' )
and run the TermDocumentMatrix( mycorpus )
function.
来源:https://stackoverflow.com/questions/51269083/error-in-nchartermsx-type-chars-invalid-multibyte-string-element-204