title: how to compare t-test in certain date ranges?
body: <p>I have a standard group for date i.e. 4-30-7.2005 </p>
  
  <p>and my reference dates are 4-30.7.2003 and 4-30.7.2004</p>
  
  <p>Now i have to compare the mean of my standard group with mean of reference dates. i.e. 4-30.7.2004 to 4-30.7.2004. </p>
  
  <p>I am using t-test to compare means separated by years using the following command: </p>
  
  <pre><code>t.test(cvd ~ format(date, "%Y"), data=hw_2010[format(hw_2010$date, "%Y")=="2003" | format(hw_2010$date, "%Y")=="2004",])
  </code></pre>
  
  <p>this is working fine. </p>
  
  <p>But how can I put reference years altogether in one group and compare those to the standard group using a t-test? can someone please help me with the code? </p>
  
  <p>Edited: I am applying the following formula for comparison: </p>
  
  <pre><code>t.test(cvd ~ format(date, "%Y")=="2010", data=hw_2010[format(hw_2010$date, "%Y") %in% c("2007","2008","2009", "2010", "2012", "2013"),])
  </code></pre>
  
  <p>but i am getting following error from R: </p>
  
  <pre><code>Error in t.test.formula(cvd ~ format(date, "%Y") == "2010", data = hw_2010[format(hw_2010$date,  : 
  </code></pre>
  
  <p>grouping factor must have exactly 2 levels</p>
  
  <p><strong>This is fixed</strong></p>