title: Anonymous function in R
body: <p>Using a dataset <em>w</em>, which includes a numeric column <em>PY</em>, I can do:</p>
  
  <pre><code>nrow(subset(w, PY==50))
  </code></pre>
  
  <p>and get the correct answer. If, however, I try to create a function:</p>
  
  <pre><code>fxn &lt;- function(dataset, fac, lev){nrow(subset(dataset, fac==lev))}
  </code></pre>
  
  <p>and run</p>
  
  <pre><code>fxn(w, PY, 50)
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Error in eval(expr, envir, enclos) : object 'PY' not found</p>
  </blockquote>
  
  <p>What am I doing wrong? Thanks.</p>