data("crude")
tdm <- TermDocumentMatrix(crude,
                          control = list(removePunctuation = TRUE,
                                         stopwords = TRUE))
dtm <- DocumentTermMatrix(crude,
                          control = list(weighting =
                                         function(x)
                                         weightTfIdf(x, normalize =
                                                     FALSE),
                                         stopwords = TRUE))
inspect(tdm[202:205, 1:5])
inspect(tdm[c("price", "prices", "texas"), c("127", "144", "191", "194")])
inspect(dtm[1:5, 273:276])
if(requireNamespace("SnowballC")) {
    s <- SimpleCorpus(VectorSource(unlist(lapply(crude, as.character))))
    m <- TermDocumentMatrix(s,
                            control = list(removeNumbers = TRUE,
                                           stopwords = TRUE,
                                           stemming = TRUE))
    inspect(m[c("price", "texa"), c("127", "144", "191", "194")])
}
Run the code above in your browser using DataLab