f_manip_data_2_model_matrix_format: brings data to model.matrix format

Description Usage Arguments Value See Also Examples

View source: R/f_manip.R

Description

model.matrix() creates dummy variables for factors. The names of these dummy variables however are not compatible with the formula syntax. This wrapper cleans up the names of the new variables.

Usage

1
2
f_manip_data_2_model_matrix_format(data, formula, scale_data = T,
  center_data = T, exclude_na_columns = T)

Arguments

data

a dataframe

formula

formula

scale_data

boolean

center_data

boolean

exclude_na_columns

boolean

Value

list with new dataframe and new formula

See Also

str_replace_all

Examples

1
2
3
4
5
6
7
8
9
data_ls = f_clean_data(mtcars)
data = data_ls$data
formula = hp ~ disp + am + gear
data_trans = f_manip_data_2_model_matrix_format( data, formula )
response_var =f_manip_get_response_variable_from_formula(data_trans$formula)
vars = f_manip_get_variables_from_formula(data_trans$formula)
x = as.matrix( select( data_trans$data, one_of(vars) ) )
y = data_trans$data[[response_var]]
glmnet::glmnet( x , y )

erblast/oetteR documentation built on Aug. 4, 2018, 11:03 p.m.