我有一个只有一列“文本”的数据框
"text"
"User Interfaces"
"Twitter"
"Text Normalization"
"Term weighting"
"Teenagers"
"Team member replacement"
我想用每个短语的频率获取一个数据框,如下所示:
"User Interfaces",1
"Twitter",1
"Text Normalization",1
"Term weighting",1
"Teenagers",1
"Team member replacement",1
为了做到这一点,我使用了这个:
library(tm)
df <- read.csv("C:/Users/acel/Desktop/myphr.csv", header=TRUE, sep=",")
corpusD <- Corpus(VectorSource(df$text))
corpusD <- tm_map(corpusD, tolower)
corpusD <- tm_map(corpusD, removeWords, stopwords('english'))
corpusD <- tm_map(corpusD, removeNumbers)
corpusD <- tm_map(corpusD, stripWhitespace)
corpusD <- tm_map(corpusD, PlainTextDocument)
corpusD <- tm_map(corpusD, stemDocument, language = "english")
corpusC <- Corpus(VectorSource(corpusD))
matrixD <- TermDocumentMatrix(corpusC)
matrixD <- removeSparseTerms(matrixD, 0.75)
MatrixDfreq <- rowSums(as.matrix(matrixD))
MatrixDfreq<-sort(MatrixDfreq, decreasing = TRUE)
MatrixDtop30<- MatrixDfreq [1:30]
但是当我检查结果时,MatrixDtop30
我看到一个单词被认为是user,1
,interface,1
而不是看到"user interface",1
知道为什么会这样吗?