[R] Using a data frame in a function call

Peter Tait petertait at sympatico.ca
Tue Oct 23 19:02:53 CEST 2007


Hi,

I am writing a basic function to extract the z scores for some linear 
regression coefficients:

zscore<-function( y, x) {
  lm<-lm( y ~ x )
  z <- coef(lm)/sqrt(diag(vcov(lm)))
  return(z)
}

I would like to pass a dataframe to the function as a argument so the 
function call changes from

zscore(df$y1,df$x1)

to

zscore(y1,x1,data=df)

but I am not sure how to reference the data frame inside the function.

Are there any good free references on how to program functions in R (besides 
the official manuals)

Thanks for your help.
Cheers
Peter



More information about the R-help mailing list