0
を許可されていない私は、次のダミーデータがあります。R:エラーにドキュメントタームマトリックスの結果を検査:繰り返しのインデックスが現在
final6 <- data.frame(docname = paste0("doc", 1:6),
articles = c("Catalonia independence in matter of days",
"Anger over Johnson Libya bodies comment",
"Man admits frenzied mum and son murder",
"The headache that changed my life",
"Las Vegas killer sick, demented - Trump",
"Instagram baby photo scammer banned")
)
をそして私は名前(私は後でリンクできることを文書化するために参照してDocumentTermMatrixを作成したいです元の記事本文へ)。これを達成するために、私はthis postからの指示に従ってください:
myReader <- readTabular(mapping=list(content="articles", id="docname"))
text_corpus <- VCorpus(DataframeSource(final6), readerControl = list(reader = myReader))
# define function that replaces ounctuation with spaces
replacePunctuation <- content_transformer(function(x) {return (gsub("[[:punct:]]"," ", x))}) # replaces punctuation with empty spaces
# remove customised words
myWords <- c("ok", "chat", 'okay', 'day', 'today', "might", "bye", "hello", "thank", "you", "please", "sorry", "hello", "hi")
# clean text
cleantext <- function(corpus){
clean_corpus <- tm_map(corpus, removeNumbers)
clean_corpus <- tm_map(clean_corpus, tolower)
clean_corpus <- tm_map(clean_corpus, PlainTextDocument)
clean_corpus <- tm_map(clean_corpus, replacePunctuation)
clean_corpus <- tm_map(clean_corpus, removePunctuation)
clean_corpus <- tm_map(clean_corpus, removeWords, c(stopwords("english"), myWords, top_names))
clean_corpus <- tm_map(clean_corpus, stripWhitespace)
clean_corpus <- tm_map(clean_corpus, stemDocument, language = "english")
clean_corpus
}
clean_corpus <- cleantext(text_corpus)
# create dtm
chat_DTM <- DocumentTermMatrix(clean_corpus, control = list(wordLengths = c(3, Inf)))
私は行列を検査する際に今、私はエラーを取得:
inspect(chat_DTM)
Error in
[.simple_triplet_matrix
(x, docs, terms) : Repeated indices currently not allowed.
が公正であるために、このエラーも発生します私がテキストだけに基づいてコーパスを作成し、doc idを属性として渡さない場合。問題の原因は何ですか?