Daniel Almirall <dalmiral <at> umich.edu> writes:
:
: R-list,
:
: Suppose I have
:
: oldfmla <- y ~ x
:
: I would like to update it to y ~ x + z which I know I can get using
:
: newfmla <- update(oldfmla, ~ . + z)
:
: However, what if I have
:
: fmlatmp <- ~ z
:
: Can I combine oldfmla and fmlatmp to get y ~ x + z some how?
:
: Clearly,
:
: newfmla <- update(oldfmla, ~ . + fmlatmp)
:
: will not work.
:
: Thanks in advance,
: Danny
Assuming we have:
old <- y ~ x
tmp <- ~ z
Then type in this:
template <- . ~ . + X
template[[3]][[3]] <- tmp[[2]]
update(old, template)
In the above we used the fact that formulas are
represented internally as trees whose parts
can be extracted using indexing. After
running the above, try entering the following to
get a better idea of how formulas are represented:
as.list(old)
as.list(tmp)
as.list(template)
as.list(template[[3]])
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html