How to rename a complex formula?

Suppose I have a formula y~x1+x2+I( (x1==x2)*x3 )and an estimate of a linear model

summary(lm(y~x1+x2+I( (x1==x2)*x3 ), data=some_data ))
Coefficients:
                   Estimate Std. Error t value Pr(>|t|)  
(Intercept)          3.6027     1.6069   2.242   0.0662 .
x1                   1.8685     1.9769   0.945   0.3811  
x2                   2.6041     2.0286   1.284   0.2466  
I((x1 == x2) * x3)   0.5666     1.5456   0.367   0.7265  

Besides creating a new "data.frame", are there any methods to change the formula so that the pivot table becomes

Coefficients:
                   Estimate Std. Error t value Pr(>|t|)  
(Intercept)          3.6027     1.6069   2.242   0.0662 .
x1                   1.8685     1.9769   0.945   0.3811  
x2                   2.6041     2.0286   1.284   0.2466  
some_name            0.5666     1.5456   0.367   0.7265  
+3
source share
1 answer

Using within, you can hack something.

Instead:

summary(lm(Sepal.Length ~ I(Sepal.Width * Petal.Length), data=iris))

#...
#(Intercept)                   4.252934   0.069396   61.28   <2e-16 ***
#I(Sepal.Width * Petal.Length) 0.142483   0.005632   25.30   <2e-16 ***
#...

You can use:

summary(lm(Sepal.Length ~ newvar, data=
         within(iris, newvar <- Sepal.Width * Petal.Length))) 

#...
#(Intercept) 4.252934   0.069396   61.28   <2e-16 ***
#newvar      0.142483   0.005632   25.30   <2e-16 ***
#...
+5
source

Source: https://habr.com/ru/post/1542414/


All Articles