toFormula: Create Formula from Left and Right Term Strings

View source: R/convert.R

toFormulaR Documentation

Create Formula from Left and Right Term Strings

Description

create a formula of the form leftterm ~ rightterms[1] + rightterms[2] + ...

Usage

toFormula(leftterm, rightterms, as.formula = TRUE)

Arguments

leftterm

character. Left term of the formula

rightterms

vector of character. Right terms of the formula to be concatenated with "+".

as.formula

if TRUE (default) the formula object is returned, otherwise the formula string (character)

Value

formula object as generated by formula or formula string (character) of the form leftterm ~ rightterms[1] + rightterms[2] + ... if as.formula is FALSE

Examples

f1 <- toFormula("y", c("x1", "x2"))
f2 <- toFormula("y", paste0("x", 1:20))
  
f3 <- toFormula("BMI", c("height", "mass"), as.formula = FALSE)
  
# f1 and f2 are formulas ...
class(f1)
class(f2)
  
# ... but f3 is just "character"
class(f3)


KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.