title: dynamic subsetting in r
body: <p>I have a data set that is something like the following, but with many more columns and rows:</p>
  <pre><code>a&lt;-c(&quot;Fred&quot;,&quot;John&quot;,&quot;Mindy&quot;,&quot;Mike&quot;,&quot;Sally&quot;,&quot;Fred&quot;,&quot;Alex&quot;,&quot;Sam&quot;)
  b&lt;-c(&quot;M&quot;,&quot;M&quot;,&quot;F&quot;,&quot;M&quot;,&quot;F&quot;,&quot;M&quot;,&quot;M&quot;,&quot;F&quot;)
  c&lt;-c(40,35,25,50,25,40,35,40)
  d&lt;-c(9,7,8,10,10,9,5,8)
  df&lt;-data.frame(a,b,c,d)
  colnames(df)&lt;-c(&quot;Name&quot;, &quot;Gender&quot;, &quot;Age&quot;, &quot;Score&quot;)
  </code></pre>
  <p>I need to create a function that will let me sum the scores for selected subsets of the data.  However, the subsets selected may have different numbers of variables each time.  One subset could be <code>Name==&quot;Fred&quot;</code> and another could be <code>Gender == &quot;M&quot;</code> &amp; <code>Age == 40</code>.  In my actual data set, there could be up to 20 columns used in a selected subset, so I need to make this as general as possible.</p>
  <p>I tried using a sapply command that included <code>eval(parse(text=...)</code>, but it takes a long time with only a sample of 20,000 or so records.  I'm sure there's a much faster way, and I'd appreciate any help in finding it.</p>