Showing string in formula and not as variable in lm fit

后端 未结 1 902
灰色年华
灰色年华 2020-12-02 02:44

I am not able to resolve the issue that when lm(sformula) is executed, it does not show the string that is assigned to sformula. I have a feeling i

相关标签:
1条回答
  • 2020-12-02 03:19

    How about eval(call("lm", sformula))?

    lm(sformula)
    #Call:
    #lm(formula = sformula)
    
    eval(call("lm", sformula))
    #Call:
    #lm(formula = "y~x")
    

    Generally speaking there is a data argument for lm. Let's do:

    mydata <- data.frame(y = y, x = x)
    eval(call("lm", sformula, quote(mydata)))
    #Call:
    #lm(formula = "y~x", data = mydata)
    

    The above call() + eval() combination can be replaced by do.call():

    do.call("lm", list(formula = sformula))
    #Call:
    #lm(formula = "y~x")
    
    do.call("lm", list(formula = sformula, data = quote(mydata)))
    #Call:
    #lm(formula = "y~x", data = mydata)
    
    0 讨论(0)
提交回复
热议问题