Coerce a dist matrix into a list of selected target terms and similar terms,
in descending order of similarity. Can be used after calling
textstat_simil
or textstat_dist
.
# S3 method for dist as.list(x, sorted = TRUE, n = NULL, ...)
x | dist class object |
---|---|
sorted | sort results in descending order if |
n | the top |
... | unused |
not_run({ ## compare to tm # tm version require(tm) data("crude") crude <- tm_map(crude, content_transformer(tolower)) crude <- tm_map(crude, remove_punctuation) crude <- tm_map(crude, remove_numbers) crude <- tm_map(crude, stemDocument) tdm <- TermDocumentMatrix(crude) findAssocs(tdm, c("oil", "opec", "xyz"), c(0.75, 0.82, 0.1)) # in quanteda quantedaDfm <- as.dfm(t(as.matrix(tdm))) as.list(textstat_simil(quantedaDfm, c("oil", "opec", "xyz"), margin = "features"), n = 14) # in base R corMat <- as.matrix(proxy::simil(as.matrix(quantedaDfm), by_rows = FALSE)) round(head(sort(corMat[, "oil"], decreasing = TRUE), 14), 2) round(head(sort(corMat[, "opec"], decreasing = TRUE), 9), 2) })