How to reliably get dependent variable name from formula object?

前端 未结 7 872
清酒与你
清酒与你 2021-01-31 02:29

Let\'s say I have the following formula:

myformula<-formula(\"depVar ~ Var1 + Var2\")

How to reliably get dependent variable name from formu

7条回答
  •  死守一世寂寞
    2021-01-31 03:27

    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

    [1] "a1" "a2"

    rhs.vars(f) #get independent variables

    [1] "a3" "a4"

提交回复
热议问题