Re: [R] A programming puzzler

About this list Date view Thread view Subject view Author view

From: Thomas Lumley (tlumley@u.washington.edu)
Date: Mon 09 Apr 2001 - 09:57:48 EST


Message-ID: <Pine.A41.4.33.0104081655020.64532-100000@homer32.u.washington.edu>

On Sat, 7 Apr 2001 fharrell@virginia.edu wrote:

> I am trying to replicate part of the function of the
> S-Plus terms.inner function. I don't need an entire
> model terms object but R expressions or character
> strings containing the innermost variable name given
> a vector of character strings or expressions. Here
> are some example inputs that each should result in the
> string or expression "x":
>
> x; x^2; g(x); h(g(x)); h(g(x^3)); j(h(g(pmin(x,3))))
> h(g(x)+g(y))
>
> To anyone who meets the challenge, thanks!

You're looking for all.vars(). It works on a formula, terms, or expression
object.

eg
> all.vars((~j(pmin(3,g(h(x^3*y))))))
[1] "x" "y"

        -thomas

Thomas Lumley Asst. Professor, Biostatistics
tlumley@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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2b30 : Fri 22 Jun 2001 - 18:58:38 EST