Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

add_intercept_column

Add an intercept column to data


Description

This function adds an integer column of 1's to data.

Usage

add_intercept_column(data, name = "(Intercept)")

Arguments

data

A data frame or matrix.

name

The name for the intercept column. Defaults to "(Intercept)", which is the same name that stats::lm() uses.

Details

If a column named name already exists in data, then data is returned unchanged and a warning is issued.

Value

data with an intercept column.

Examples

add_intercept_column(mtcars)

add_intercept_column(mtcars, "intercept")

add_intercept_column(as.matrix(mtcars))

hardhat

Construct Modeling Packages

v0.1.5
MIT + file LICENSE
Authors
Davis Vaughan [aut, cre], Max Kuhn [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.