Gabor Grothendieck <ggrothendieck <at> myway.com> writes:

: 
: 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)
: 

One can alternately use substitute avoiding determination of
the precise indices of X.  Note that the eval is required
since substitute returns a call object and eval turns it
back into a formula (as per the Note near the bottom of
?substitute):

       tmp2 <- eval(substitute(. ~ . + X, list(X = tmp[[2]])))
       update(old, tmp2)

______________________________________________
[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

Reply via email to