Ich bin sehr neu in Text Mining, aber ich wollte Analyse Tweets über einen bestimmten Zeitraum.Konvertieren von Matrix zurück in eine DocumentTermMatrix
Ich habe vor Wochen Tweets von Twitter gekratzt und komme erst jetzt zur Analyse. Ich habe die DocumentTermMatrix als Matrix gespeichert und stehe vor der Schwierigkeit, sie wieder in eine DocumentTermMatrix umzuwandeln, um eine latente Dirichlet-Zuordnung für die Daten vorzunehmen.
scrap<- searchTwitter("#RepealThe8th", n=1500)
twscrap <- sapply(scrap, function(x) x$getText())
corpus1 <- Corpus(VectorSource(twscrap))
corpus1 <- tm_map(corpus1,
content_transformer(function(x) iconv(x, to='UTF-8-MAC', sub='byte')),
mc.cores=1)
corpus1 <- tm_map(corpus1, content_transformer(tolower), mc.cores=1)
corpus1 <- tm_map(corpus1, removePunctuation, mc.cores=1)
corpus1 <- tm_map(corpus1, function(x)removeWords(x,stopwords()), mc.cores=1)
corpus1 <- tm_map(corpus1, stemDocument, mc.cores=1)
myStopwords = c("https", "http");
idx = which(myStopwords == "r");
myStopwords = myStopwords[-idx];
corpus1 = tm_map(corpus1, removeWords, myStopwords);
corpus1 <- tm_map(corpus1, stripWhitespace)
plaincorpus1 <- tm_map(corpus1, PlainTextDocument)
dtm <- DocumentTermMatrix(plaincorpus1, control = list(minWordLength = 3));
m <- as.matrix(dtm)
Das war, wie ich die Daten ursprünglich gespeichert
write.csv(m, "matrix.csv")
Wenn ich die Daten laden in ich es nicht zurück in DTM Form bekommen
m <- read.csv("matrix.csv",header=TRUE)
corpNR<-Corpus(DataframeSource(xNR))
dtmNR<-DocumentTermMatrix(corpNR)
dtmNR$dimnames$Terms <- colnames(xNR) #add terms to DocTermMetrix
str(dtmNR)
dtmNR$ncol <- length(dtmNR$dimnames$Terms) #give it the right no. of cols
Das gibt mir einen DTM auf der rechten Seite, aber ich bin mir nicht sicher, wie man die richtigen Daten für dtmNR $ i, dtmNR $ j oder dtmNR $ v
Ich habe auch versucht
library(qdap)
m1 <- as.Corpus(m)
#Error in data.frame(grouping, text.var, check.names = FALSE, stringsAsFactors = FALSE) :
# arguments imply differing number of rows: 2062, 1500
#dtm1 <- as.DocumentTermMatrix(m1)
dtm1 <- as.TermDocumentMatrix(m1)
#Error in .TermDocumentMatrix(t(x), weighting) :
# argument "weighting" is missing, with no default
Das merke ich jetzt, aber ich habe bereits die Daten in CSV-Dateien gespeichert – Una