我对R很新,并且不能完全围绕DocumentTermMatrixs.我有一个使用TM包创建的DocumentTermMatrix,它有术语频率和其中的术语,但我无法弄清楚如何访问它们.
理想情况下,我想:
Term #
"the" 200
"is" 400
"a" 200
Run Code Online (Sandbox Code Playgroud)
目前我的代码是:
library(tm)
common.words <- c("amp","@RT","I","http","https", stopwords("english"), "you")
x <- Corpus(VectorSource(results))
x <- tm_map(x, stripWhitespace)
x <- tm_map(x, removeNumbers)
x <- tm_map(x, removePunctuation)
x <- tm_map(x, stripWhitespace)
dtm <- DocumentTermMatrix(x)
for(i in 1:length(common.words)) {
dtm <- dtm[,!colnames(dtm)%in%c(common.words[i])]
}
Run Code Online (Sandbox Code Playgroud)
这是str(dtm)的输出
List of 6
$ i : int [1:9769] 1 1 1 1 1 1 1 1 2 2 ...
$ j : int [1:9769] 1596 1684 1858 2112 2175 2490 2714 2814 …Run Code Online (Sandbox Code Playgroud)