to_sparse_matrix: Convert a data frame to a dgCMatrix object

Description Usage

View source: R/to_sparse_matrix.R

Description

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".

Usage

1

chaoguo14/crowbar documentation built on Aug. 16, 2021, 9:51 p.m.