format_formula: Format character arguments into R Formula

Description Usage Arguments Value Examples

View source: R/miscutils.R

Description

takes in arguments for y and x and returns formula in the form y ~ x. Capable of handling complex formulas, returning them in the form y ~ x1 + x2 + x2 * x3 \* x4 + x2 ^ 2 + x3 ^ 0.5... Inputs are in the form of vectors or lists of characters associated with each operation, with handling for +, * and ^.

Usage

1
format_formula(y, xadd = NULL, xmultiply = NULL, xpower = NULL, power = 2)

Arguments

y

the target variable

xadd

a vector of column name arguments to be added together (a+b...) in the formula

xmultiply

a vector of column name arguments to be multiplied together (e.g. xmultiply = c(a,b,c) -> a*b\*c) or a list of seperate sets of column names arguments to be multiplied and added together (e.g. xmultiply = list(c(a,b,c),c(b,c)) -> a*b\*c+b\*c )

xpower

a vector of column name arguments to be elevated to the power of power (e.g. xpower = c(a,b,c), power = 2 -> a^2+b^2+c^2) or a list of (column name, power) pairs to be added together (e.g. xpower = list(c(a,2),c(b,0.5)) -> a^2+b^0.5)

power

an optional power to elevate all the values of xpower (default = 2)

Value

a formula in the form y~xadd+xmultiply+xpower

Examples

1
2
3
4
5
6
7
8
9
format_formula('y', xadd=c('a','b'))
format_formula('y', xmultiply=c('a','b'))
format_formula('y', xmultiply=list(c('a','b','c'), c('c','a')))
format_formula('y', xpower=c('a','b'))
format_formula('y', xpower=c('a','b'), pow=0.5)
format_formula('y', xpower=list(c('a',2), c('b',0.5)))
format_formula('y', xadd=c('a','b'),
xmultiply=list(c('a','b','c'),c('c','a')),
xpower=list(c('a',2), c('b',0.5)))

duncankmckinnon/OKdplyr documentation built on Nov. 30, 2020, 1:13 a.m.