I can build a formula that does what I want, starting with the symbolic versions of the terms in the formula, but I stumble starting from the formula object:
form1 <- Y ~ A + B
form1[-c(1,2)][[1]]
Now, how to build a formula object that looks like this:
Y ~ poly(A, 2) + poly(B, 2) + poly(C, 2)
Or:
Y ~ pspline(A, 4) + pspline(B, 4) + pspline(C, 4)
It seems like it could be a recursive walk on RHS, but I am not getting progress. It just occurred to me that I can use
> attr( terms(form1), "term.labels")
[1] "A" "B"
And then use the approach as.formula(character-expr), but I really like to see the version of the lapply (RHS_form, somefunc)function polyize(or maybe polymer?).
source
share