title: R: wilcoxon test Error: Grouping Factor must have exactly 2 levels
body: <p>I read <a href="https://stackoverflow.com/questions/29421475/basic-t-test-grouping-factor-must-have-exactly-2-levels">this SO question</a> and <a href="https://stackoverflow.com/questions/21148658/r-ttest-inside-ddply-gives-error-grouping-factor-must-have-exactly-2-levels">that one</a>, but still could not solve my problem. I have the following data.table which includes only a few of my total columns and rows of my data.table.</p>
  
  <pre><code>library(data.table)
  structure(list(Patient = c("MB108", "MB108", "MB108", "MB108", 
  "MB108", "MB108", "MB108", "MB108", "MB108", "MB108"), Visit = c(1, 
  1, 1, 1, 9, 9, 9, 9, 12, 12), Stimulation = c("NC", "SEB", "PPD", 
  "E6C10", "NC", "SEB", "PPD", "E6C10", "NC", "SEB"), `CD38   ` = c(83.3, 
  63.4, 83.2, 91.5, 90.9, 70.9, 71, 88.4, 41.7, 47.9)), .Names = c("Patient", 
  "Visit", "Stimulation", "CD38   "), class = c("data.table", "data.frame"
  ), row.names = c(NA, -10L), .internal.selfref = &lt;pointer: 0x102806578&gt;)
  </code></pre>
  
  <p>I would like to do a t.test on column 4 when visit is 1 and when visit is 9. 
  I checked for NAs as well as the length of both columns. </p>
  
  <p>Thanks for any help!</p>
  
  <pre><code>      #na.omit(boolean_dt3)
        #print(length(unlist(boolean_dt3[Visit== 1,4, with = FALSE])))
        #print(length(unlist(boolean_dt3[Visit== 9,4, with = FALSE])))
  
  wilcox.test( unlist(boolean_dt3[Visit== 1,4, with = FALSE])~ unlist(boolean_dt3[Visit== 9,4, with = FALSE]) , paired = T, correct=FALSE)
  </code></pre>