Skip to content
Prev 318573 / 398503 Next

Multiple left hand side variables in a formula

I don't know how much of the information that model.frame supplies you need,
but you could make a data.frame containing all the variables on both sides of them
formula by changing lhs~rhs into ~lhs+rsh before calling model.frame.  E.g.,

f <- function (formula)  {
    if (length(formula) == 3) { # has left hand side
        envir <- environment(formula)
        formula <- formula(call("~", call("+", formula[[2]],  formula[[3]])))
        environment(formula) <- envir
    }
    formula
}

This doesn't quite take care of the wild-card dot in the formula: straight
variables are omitted from dot's expansion but functions of variables are
not:
[1] "log(mpg)" "hp"       "mpg"      "cyl"     
 [5] "disp"     "drat"     "wt"       "qsec"    
 [9] "vs"       "am"       "gear"     "carb"    

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com