[R] terms() and I( ) -- extract variables names only
Álvaro A. Novo
novo at uiuc.edu
Thu Dec 21 22:44:49 CET 2000
Hi,
I am having difficulties extracting all variables used in a formula. Here's
an example of what I am doing:
> my.formula <- v1 ~ v2 + v3 + I(v4/v5)
> out.terms <- terms(my.formula)
> paste(attr(out.terms, "variables"))[-1]
[1] "v1" "v2" "v3" "I(v4/v5)"
BUT what I would like to get is
[1] "v1" "v2" "v3" "v4" "v5"
Also, if I change I(v4/v5) to I(v4^2) or any other expression, it should only
extract the variable (here, V4).
Is there a built-in function to do it? Suggestions are extremely appreciated.
Thank you for your attention,
Alvaro A. Novo
R-1.2.0
Linux SuSE 6.4
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list