[R] using update( ) in a function?
    Mahmood ARAI 
    ma at ne.su.se
       
    Mon Apr 21 19:23:52 CEST 2003
    
    
  
Hello, 
using the function "update()" in the following function
does not work. 
# a function for running a model:  x1 ~ x2
# by updating the original model: fm1 <- lm(y ~ x1 + x2,data=df)
# update(fm1, x1 ~ . -x1, data=df) works at the command line
# but not in the function below. 
R>   foo <- function(fm,x,df)
+     {
+     update(fm, x ~ . -x,data=df)
+     }
R>
R>
R>  df1 <- data.frame(y= 1:10, x1=(1:10)^2, x2=sqrt(1:10)^3)
R>  fm1 <- lm(y ~ x1+x2, data=df1)
R>
R>  foo(fm1, x1, df1)
Error in eval(expr, envir, enclos) : Object "x" not found
R>  update(fm1, x1 ~ . -x1,data=df1) 
Call:
lm(formula = x1 ~ x2, data = df1) 
Coefficients:
(Intercept)           x2
    -7.753        3.242 
any idea? 
thanks!
mahmood arai
    
    
More information about the R-help
mailing list