title: Running a two-sample t.test with unequal sample size in R
body: <p>I am trying to run a two-sample t-test for a difference between a treatment and control group. Data is not paired. When I subset my original dataframe, I found that I have unequal sample sizes (not an issue by hand, but R seems to make it an issue). Here is my code:</p>
  
  <pre><code>CG&lt;-subset(data,treat=="Control")
  TG&lt;-subset(data,treat!="Control")
  agep &lt;-t.test(CG$age~TG$age)$p.value
  </code></pre>
  
  <p>The error I get is the following:</p>
  
  <pre><code>Error in model.frame.default(formula = CG$age ~ TG$age) : 
  variable lengths differ (found for 'TG$age')
  </code></pre>
  
  <p>Yes! The lengths do differ. Not sure why that's a problem if I'm not running a paired test? Thanks in advance for any help.</p>