Rebecca,

you can keep formula as a character vector that can be easily manipulated

formula1 <- "Y~X1+X2+X3"
formula2 <- gsub("Y","newY",formula1)

lm(as.formula(formula1),data=mydata)
lm(as.formula(formula2),data=mydata)

best,
peter


On 10/1/07, Rebecca Sela <[EMAIL PROTECTED]> wrote:
>
> I am writing a program in which I would like to take in a formula, change
> the response (Y) variable into something else, and then pass the formula,
> with the new Y variable to another function.  That is, I am starting with
>          formula <- Y~X1+X2+X3
> and I'd like to do something like
>          Y <- formula$Y
>          newY <- f(Y)
>          lm(newY~X1+X2+X3)
> So far, it seems that my only option will be a very complicated sequence
> of steps involving match.call().  Is there a simpler way to change the
> response variable in a formula?
>
> Thanks in advance!
>
> Rebecca
>
> --
> Rebecca Sela
> Statistics Department
> Stern School of Business
> New York University
>
> ______________________________________________
> R-help@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.
>



-- 
Peter Salzman, PhD
Department of Biostatistics and Computational Biology
University of Rochester

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to