[R] update.formula drop interaction terms
Eleni Rapsomaniki
er339 at medschl.cam.ac.uk
Tue Oct 13 15:45:50 CEST 2009
Dear R users,
How do I drop multiplication terms from a formula using update?
e.g.
forml=as.formula("Surv(time, status) ~ x1+x2+A*x3+A*x4+B*x5+strata(sex)")
#I would like to drop all instances of variable A (the main effect and its interactions). The following:
updated.forml=update(forml, ~ . -A)
#gives me this:
#Surv(time, status) ~ x1 + x2 + x3 + x4 + B + x5 + strata(sex) + A:x3 + A:x4 + B:x5
#but I want this:
#updated.forml=as.formula("Surv(time, status) ~ x1+x2+x3+x4+B*x5+strata(sex)")
Any ideas?
Thanks in advance
Eleni Rapsomaniki
Research Associate
Strangeways Research Laboratory
Department of Public Health and Primary Care
University of Cambridge
More information about the R-help
mailing list