| to_matrix | R Documentation |
Given an object creates a design matrix.
to_matrix(x, with_intercept = FALSE, remove_na = FALSE)
x |
( |
with_intercept |
( |
remove_na |
( |
The following rules are applied when converting the object to matrix depending the object's type:
numeric vector: It is converted to a one column matrix.
character, logical or factor vectors: All of these are considered
to be categorical variables and therefore a dummy matrix is created with
all categories (or unique values) without the firts one, so a
n x (categories_number - 1) matrix is created.
data.frame: All columns are included but character, logical or
factor are included in the same way as described for vectors.
For all the columns a name is assigned if they has no one.
The intercept is always added at the first column with the name
"(Intercept)".
A matrix.
## Not run:
to_matrix(iris)
to_matrix(1:10)
to_matrix(c("a", "b", "c"))
to_matrix(data.frame(a = c("a", "b"), b = c("c", "d")))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.