poly_add_columns {polypoly}R Documentation

Add orthogonal polynomial columns to a dataframe

Description

Add orthogonal polynomial columns to a dataframe

Usage

poly_add_columns(
  .data,
  .col,
  degree = 1,
  prefix = NULL,
  scale_width = NULL,
  na_values = c("error", "warn", "allow")
)

Arguments

.data

a dataframe

.col

a bare column name

degree

number of polynomial terms to add to the dataframe

prefix

prefix for the names to add to the dataframe. default is the name of .col.

scale_width

optionally rescale the dataframe using poly_rescale(). Default behavior is not to perform any rescaling.

na_values

How to handle missing values. Default is "error" which raises an error. Other options include "warn" to raise a warning and "allow" to silently accept missing values.

Value

the dataframe with additional columns of orthogonal polynomial terms of .col

Examples

df <- data.frame(time = rep(1:5, 3), y = rnorm(15))

# adds columns "time1", "time2", "time3"
poly_add_columns(df, time, degree = 3)

# adds columns "t1", "t2", "t3 and rescale
poly_add_columns(df, time, degree = 3, prefix = "t", scale_width = 1)

[Package polypoly version 0.0.3 Index]