% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/util.R
\name{get_data_from_formula}
\alias{get_data_from_formula}
\title{Extracts design matrix from a formula and data.}
\usage{
get_data_from_formula(form, data)
}
\arguments{
\item{form}{A formula object, e.g., `~ x1 + x2` or `~.`.}

\item{data}{A data frame or matrix from which to extract the design matrix.}
}
\value{
A numeric matrix representing the design matrix.
}
\description{
This function takes a formula and a data frame, and returns a design matrix
based on the right-hand side of the formula. If the formula is `~.`, it treats
all columns in the data as the design matrix. Otherwise, it constructs a
design matrix without an intercept based on the specified formula.
}
\examples{
data(mtcars)
# Extract a design matrix for 'mpg' and 'cyl'
X1 <- get_data_from_formula(~ mpg + cyl, mtcars)
# Extract a design matrix for all columns
X2 <- get_data_from_formula(~., mtcars)
# Extract a design matrix for 'hp'
X3 <- get_data_from_formula(~hp, mtcars)
}
