Let\'s say I have the following formula:
myformula<-formula(\"depVar ~ Var1 + Var2\")
How to reliably get dependent variable name from formu
I found an useful package 'formula.tools' which is suitable for your task.
code Example:
f <- as.formula(a1 + a2~a3 + a4) lhs.vars(f) #get dependent variables
f <- as.formula(a1 + a2~a3 + a4)
lhs.vars(f) #get dependent variables
[1] "a1" "a2"
rhs.vars(f) #get independent variables
[1] "a3" "a4"