[R] terms() and I( ) -- extract variables names only
Thomas Lumley
thomas at biostat.washington.edu
Thu Dec 21 22:54:10 CET 2000
On Thu, 21 Dec 2000, [iso-8859-1] Álvaro A. Novo wrote:
> 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.
all.vars()
-thomas
Thomas Lumley Asst. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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