weight(x, ...)## S3 method for class 'dfm':
weight(x, type = c("frequency", "relFreq", "relMaxFreq",
"logFreq", "tfidf"), ...)
smoother(x, smoothing)
weighting(object)
## S3 method for class 'dfm':
weighting(object)
weighting
returns a character object describing the type of weighting applied to the dfm.
smoother(x, smoothing)
is a shortcut for weight(x, "frequency", smoothing)
weighting
queries (but cannot set) the weighting applied to the dfm.
tfidf
dtm <- dfm(inaugCorpus)
x <- apply(dtm, 1, function(tf) tf/max(tf))
topfeatures(dtm)
normDtm <- weight(dtm, "relFreq")
topfeatures(normDtm)
maxTfDtm <- weight(dtm, type="relMaxFreq")
topfeatures(maxTfDtm)
logTfDtm <- weight(dtm, type="logFreq")
topfeatures(logTfDtm)
tfidfDtm <- weight(dtm, type="tfidf")
topfeatures(tfidfDtm)
# combine these methods for more complex weightings, e.g. as in Section 6.4 of
# Introduction to Information Retrieval
head(logTfDtm <- weight(dtm, type="logFreq"))
head(tfidf(logTfDtm, normalize = FALSE))
testdfm <- dfm(inaugTexts[1:5], verbose = FALSE)
for (w in c("frequency", "relFreq", "relMaxFreq", "logFreq", "tfidf")) {
testw <- weight(testdfm, w)
cat("\n\n=== weight() TEST for:", w, "; class:", class(testw), "\n")
head(testw)
}
Run the code above in your browser using DataLab