Re: [R] updating formula inside function

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 12 Jan 2006 - 08:52:12 EST

This was just discussed last week:

https://www.stat.math.ethz.ch/pipermail/r-help/2006-January/083812.html

On 1/11/06, Christian Bieli <bieli@biomillaufen.ch> wrote:
> Dear R-Helpers
>
> Given a function like
> foo <- function(data,var1,var2,var3) {
> f <- formula(paste(var1,'~',paste(var2,var3,sep='+'),sep=''))
> linmod <- lm(f)
> return(linmod)
> }
> By typing
> foo(mydata,'a','b','c')
> I get the result of the linear model a~b+c.
> How can I rewrite the function so that the formula can be updated inside
> the function, i.e.
> foo <- function(data,var1,var2,var3,var4) {
> f <- formula(paste(var1,'~',paste(var2,var3,sep='+'),sep=''))
> linmod <- lm(f)
> return(linmod)
> f2 <- update.formula(f,.~.-var3+var4)
> }
> Like that it won't work because var3 and var4 are characters, but also
> with substitute() and eval() I did not manage to get the favoured result.
> Can somebody help me out?
> Thank you in advance
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jan 12 08:57:57 2006

This archive was generated by hypermail 2.1.8 : Thu 12 Jan 2006 - 14:09:28 EST