title: Paired t-test in R
body: <p>I am trying to run a paired t-test in R on data grouped by factors: </p>
  
  <pre><code>&gt; head(i.o.diff,n=20)
  #   Difference Tree.ID Tree.Name   Ins Outs
  #1        0.20    AK-1      Akun  1.20  1.0
  #2       -1.60    AK-2      Akun  0.40  2.0
  #3       -0.60    AK-3      Akun  1.40  2.0
  #4        0.40    AK-4      Akun  0.40  0.0
  #5        1.30    AK-5      Akun  1.80  0.5
  #6        2.70     J-1     Jaror 10.20  7.5
  #7        6.60     J-2     Jaror 10.60  4.0
  #8        2.50     J-3     Jaror  6.00  3.5
  #9        7.50     J-4     Jaror 22.00 14.5
  #10      -4.50     J-5     Jaror  5.00  9.5
  #11       3.50    Ce-1     Ku'ch  4.00  0.5
  #12      -0.70    Ce-2     Ku'ch  4.80  5.5
  #13       1.60    Ce-3     Ku'ch  2.60  1.0
  #14      -2.40    Ce-4     Ku'ch  2.60  5.0
  #15      -1.75    Ce-5     Ku'ch  2.25  4.0
  </code></pre>
  
  <p>I first tried using:</p>
  
  <pre><code>pairwise.t.test(i.o.diff$In,i.o.diff$Out,g=i.o.diff$Tree.Name,paired=TRUE,pool=FALSE,p.adj="none",alternative=c("less"),mu=0)
  </code></pre>
  
  <p>but I get the error</p>
  
  <blockquote>
    <p>Error in complete.cases(x, y) : not all arguments have the same length</p>
  </blockquote>
  
  <p>which doesn't make a whole lot of sense to me.  </p>
  
  <p>I considered using <code>ddply()</code>, <code>apply()</code>, and <code>summaryBy()</code>, but couldn't get it to work because the inputs for the paired t-test require 2 vectors and most of the previous functions I mention seem to work best when only one column is being "operated" upon.</p>
  
  <p>In order to get around this, I tried to use a for loop to achieve the same end:</p>
  
  <pre><code>for(i in unique(i.o.diff$Tree.Name)) {
    pair_sub&lt;-subset(i.o.diff,Tree.Name==i) 
    t.pair&lt;-t.test(pair_sub$Ins,pair_sub$Outs,paired="True")
    print(t.pair)
  }
  </code></pre>
  
  <p>However when I do this, I get error</p>
  
  <blockquote>
    <p>in paired || !is.null(y) : invalid 'x' type in x||y</p>
  </blockquote>
  
  <p>So I checked <code>typeof(pair_sub$Ins)</code>. Turns out that type is double, which is numeric, so I am not sure why the paired t-test is not working.  Any ideas as to how to fix either of these methods?</p>