Learn R Programming

hardhat (version 1.3.1)

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

Value

data with an intercept column.

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.

Examples

Run this code
add_intercept_column(mtcars)

add_intercept_column(mtcars, "intercept")

add_intercept_column(as.matrix(mtcars))

Run the code above in your browser using DataLab