sparse_dummy | R Documentation |
Generate sparse dummy variables
sparse_dummy(x, one_hot = TRUE)
x |
A factor. |
one_hot |
A single logical value. Should the first factor level be
included or not. Defaults to |
Only factor variables can be used with sparse_dummy()
. A call to
as.factor()
would be required for any other type of data.
If only a single level is present after one_hot
takes effect. Then the
vector produced won't be sparse.
A missing value at the i
th element will produce missing values for all
dummy variables at thr i
th position.
A list of sparse integer dummy variables.
x <- factor(c("a", "a", "b", "c", "d", "b"))
sparse_dummy(x, one_hot = FALSE)
x <- factor(c("a", "a", "b", "c", "d", "b"))
sparse_dummy(x, one_hot = TRUE)
x <- factor(c("a", NA, "b", "c", "d", NA))
sparse_dummy(x, one_hot = FALSE)
x <- factor(c("a", NA, "b", "c", "d", NA))
sparse_dummy(x, one_hot = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.