From: Manuel Morales <Manuel.A.Morales_at_williams.edu>

Date: Fri 27 Oct 2006 - 21:18:05 GMT

*}
*

*}
*

Date: Fri 27 Oct 2006 - 21:18:05 GMT

data <- data.frame(a=c(1:10),b=c(1:10))

eg.fn <- function(expr, data) {

x <- eval(substitute(expr), envir=data) return(mean(x))

eg.fn(a,data)

I've tried various approaches to add a subset argument to the example above, but no luck. I'm looking for something like the following (but that works!)

eg.fn2 <- function(expr, data, subset) {

data <- subset(data,subset) x <- eval(substitute(expr), envir=data) return(mean(x))

eg.fn2(a, data, subset=a>3)

This returns the error:

"Error in eg.fn2(a, data, subset = a > 3) :

object "a" not found"

Any suggestions?

Thanks!

-- Manuel A. Morales http://mutualism.williams.eduReceived on Sat Oct 28 07:26:29 2006

______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.

- application/pgp-signature attachment: This is a digitally signed message part

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Fri 27 Oct 2006 - 22:30:14 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.
*