Learn R Programming

twidlr (version 0.0.0.9000)

model_as_xy: Convert data frame and model

Description

Convert a data frame and model formula to a list containing the input variables as a matrix x and the output variable as a vector y. These structures are commonly used by various modelling functions such as glmnet.

Usage

model_as_xy(data, formula)

Arguments

data
A data frame
formula

Value

Two-element list containing input variables as a matrix x, and output variable as a vector y

Details

All operators made available by formula are allowed.

See Also

formula model.matrix

Examples

Run this code
model_as_xy(mtcars, hp ~ mpg)
model_as_xy(mtcars, hp ~ .)
model_as_xy(mtcars, hp ~ mpg * hp)
model_as_xy(mtcars, ~ .)

Run the code above in your browser using DataLab