| %BC% | R Documentation |
Collapse a binary indicator matrix into a character vector of labels. For each
row, the labels of all columns equal to 1 are pasted together, comma-separated.
This is the inverse of multi-hot encoding: unlike one_hot2factor, which assumes
a single 1 per row, %BC% supports rows with multiple 1s (multi-label data, e.g.
multiple-choice survey responses, tags, or set membership). Rows of all zeros
return NA.
x %BC% labels
x |
A binary matrix or data.frame |
labels |
Character vector length equal to |
a character vector
EDG
# Multi-hot matrix: each row can belong to multiple categories
x <- rbind(
c(1, 0, 1),
c(0, 1, 0),
c(1, 1, 1),
c(0, 0, 0)
)
labels <- c("apple", "banana", "cherry")
x %BC% labels
# -> "apple,cherry", "banana", "apple,banana,cherry", NA
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.