title: R: Calculate means for subset of a group
body: <p>I want to calculate the mean for each "Day" but for a portion of the day (Time=12-14). This code works for me but I have to enter each day as a new line of code, which will amount to hundreds of lines. </p>
  
  <p>This seems like it should be simple to do. I've done this easily when the grouping variables are the same but dont know how to do it when I dont want to include all values for the day. 
  Is there a better way to do this?</p>
  
  <pre><code>sapply(sap[sap$Day==165 &amp; sap$Time %in% c(12,12.1,12.2,12.3,12.4,12.5,13,13.1,13.2,13.3,13.4,13.5, 14), ],mean)
  
  sapply(sap[sap$Day==166 &amp; sap$Time %in% c(12,12.1,12.2,12.3,12.4,12.5,13,13.1,13.2,13.3,13.4,13.5, 14), ],mean)
  </code></pre>
  
  <p>Here's what the data looks like:</p>
  
  <pre><code>Day Time    StomCond_Trunc
  165 12      33.57189926
  165 12.1    50.29437636
  165 12.2    35.59876214
  165 12.3    24.39879768
  </code></pre>