[R] Subscripting specified variables in a function

From: Zodet, Marc W. (AHRQ) <Marc.Zodet_at_ahrq.hhs.gov>
Date: Tue, 26 Jun 2007 10:42:39 -0400

I'm trying to create a function which will allow me to subset a data set based on values of various specified variables. I also want to then apply some other function(s) (e.g., summary).  

This is what I've tried so far....  

> test.fx <- function(dta, expvar, expval) {

+ newdta <- subset(dta, eval(expvar)>expval)

+ summary(newdta$eval(expvar))

+ }


> test.fx(fyc04s, quote(totexp04), 100)

Error in summary(newdta$eval(expvar)) : attempt to apply non-function


The subset works fine, but the my attempt to access the specified variable bombs.  

Is there a syntactical change I can make?

Is it better to attach newdta?  

Thanks in advance for any guidance.  


Marc W. Zodet, MS

Senior Health Statistician

Agency for Healthcare Research and Quality

Center for Financing, Access, and Cost Trends

301-427-1563 (Telephone)

301-427-1276 (Fax)


        [[alternative HTML version deleted]]

R-help_at_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 and provide commented, minimal, self-contained, reproducible code. Received on Tue 26 Jun 2007 - 15:21:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Jun 2007 - 00:32:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.