Skip to content
Prev 243653 / 398513 Next

How to pass selection criteria in a function

On Wed, 1 Dec 2010, CMcCarthy at bmcc.cuny.edu wrote:

            
Simple? Maybe not so much!

You are trying to pass objects without evaluating them. subset is rather 
special in the way it works. Here is one way:
+ mc <- match.call()
+ mc[[1]] <- as.name("subset")
+ eval(mc)
+ }
Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
101          6.3         3.3          6.0         2.5 virginica
110          7.2         3.6          6.1         2.5 virginica
145          6.7         3.3          5.7         2.5 virginica


Reading the code at the top of lm shows how this kind of strategy can be 
used.

You might look at

 	?bquote

for another way to skin this cat.


HTH,

Chuck
Charles C. Berry                            Dept of Family/Preventive Medicine
cberry at tajo.ucsd.edu			    UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901