Displaying 2 results from an estimated 2 matches for "newfmla".
Did you mean:
newfile
2012 May 29
3
trouble automating formula edits when log or * are present; update trouble
..., y=rnorm(100))
m1 <- lm(y ~ log(x1) + x1 + sin(x2) + x2 + exp(x3), data=dat)
m2 <- lm(y ~ log(x1) + x2*x3, data=dat)
suffixX <- function(fmla, x, s){
upform <- as.formula(paste0(". ~ .", "-", x, "+", paste0(x, s)))
update.formula(fmla, upform)
}
newFmla <- formula(m2)
newFmla
suffixX(newFmla, "x2", "c")
suffixX(newFmla, "x1", "c")
The last few lines of the output. See how the update misses x1 inside
log(x1) or in the interaction?
> newFmla <- formula(m2)
> newFmla
y ~ log(x1) + x2 * x3
> su...
2012 Jun 12
0
Working on a Vignette called Rcheology
...hat touch on things that expose special features of the R
language. Right now, I've only got one worked out, it explores this
idiom that Gabor G. explained to me, which receives a formula object
and replaces a variable "x1" with "x1c".
do.call("substitute", list(newFmla, setNames(list(as.name("x1c")), "x1")))
I think that one is fabulous, It sheds a lot of light when you break
it down to pieces.
I'd like to build up a good list of "Do This, Not That" bits, but it
is hard to find particular approaches that almost all of you will...