Skip to content
Back to formatted view

Raw Message

Message-ID: <AANLkTinBC1Cv_nJDkVSo_7Z+TieUcCP9h10o1T45F3Po@mail.gmail.com>
Date: 2011-01-23T20:44:04Z
From: Joshua Wiley
Subject: Passing formula as an agrument
In-Reply-To: <935509.87552.qm@web57506.mail.re1.yahoo.com>

Hi Tim,

I already answered this exact question from a different poster (by the
name of Paul Evans, subject: "Passing in arguments into function"),
that occurred within marvelous temporal proximity to your own, so I
will just refer you to that (search the archives with name + subject).

Just as a note, diff() is a function, so it is probably best to give
the variable you store the results of a call to lm() in a different
name, even if it is trivially different:

diff1 <- lm(x ~ y + z)

It can help to prevent future confusion and headache.

Cheers,

Josh

On Sun, Jan 23, 2011 at 8:44 AM, Tim Smith <tim_smith_666 at yahoo.com> wrote:
> Hi,
>
> I had a function that looked like:
>
> diff <- lm(x ~ y + z)
>
> How can I pass the argument to the 'lm' function on the fly? E.g., if I pass it
> in as a string (e.g. "x ~ y + z"), then the lm function treats it as a string
> and not a proper argument.
>
> many thanks
>
>
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/