View source: R/utils-embedding-vectors.R
| get_centroids | R Documentation |
Compute multiple centroids in a single call, either from a list of anchor
term sets (word-vector mode) or from a feature matrix with a grouping
vector (feature-matrix mode). The plural counterpart to
get_centroid().
get_centroids(fv, anchors = NULL, groups = NULL, missing = "stop")
fv |
Matrix or sparse |
anchors |
List of anchor term vectors. Each element is passed to
|
groups |
Vector of group labels of the same length as
|
missing |
Character scalar. Either |
Matrix with one row per centroid and ncol(fv) columns.
Rownames are the names of anchors (or the levels of groups).
Dustin Stoltz
get_centroid()
data(ft_wv_sample)
## word-vector mode: named list of anchor sets
anchors <- list(
space = c("spacecraft", "rocket", "moon"),
water = c("ocean", "sea")
)
cens <- get_centroids(ft_wv_sample, anchors = anchors)
## feature-matrix mode: group rows of a matrix by a label vector
mat <- ft_wv_sample[1:10, , drop = FALSE]
labs <- rep(c("a", "b"), each = 5)
cens <- get_centroids(mat, groups = labs)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.