View source: R/to_sparse_matrix.R
This function converts a data frame to a dgCMatrix object. This is a sparse matrix object and can be feeded to, for example, xgboost().
The input data frame should only contain numeric and/or factor. The returned dgCMatrix will have column names.
If a column is numeric, then the function keeps its original column name. If a column is a factor, it will be expanded into multiple columns using one-hot encoding. The new column names will look like factor_level. For example, if a column named "gender" contains "M" and "F", then this column will become two columns, with names "gender_M" and "gender_F".
1 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.