We the moody Gucci, Louis and Pucci men
The chopper it got the Uzi lens
The birds I knew, flip birds
Bird gangs, it was birds I flew
Say you use the base #rstats
lm(data=dat_foo[,c('y','x1','x2')],y ~ x1 + x2 + x1:x2)
I want to be able to map the single formula term
x1:x2 to the two
In words, for a term in a
?formula, lookup the involved ‘root’ columns of the data frame inside the formula’s associated environment.
I feel like this mapping must exist under the
lm() hood somewhere. Various stackoverflow Q+A’s about formulas never directly talk about this lookup. This Rviews blog post sums up the formula landscape pretty well. But there does not seem to be a convenient expose of the explicit lookup/hash table of the df to term mapping.
I have to hand roll the few lines of code to implement the hash / lookup table myself. My solution is ‘loose’ since it chops up the terms in the formula, then creates many sub-formulas for each chopped term.
Is there a better / preferred way?