title: wilcox.test() on many combinations of columns
body: <p>I have a data.table with approximately 400 columns and 800,000 rows. The columns represent samples and the rows represent CpG sites. Example data here:</p>
  <pre><code>require(data.table)
  samples &lt;- replicate(200,replicate(1000,runif(1)))
  cpgs &lt;- paste0('cpg',1:1000)
  n &lt;- c('cpg',paste0('sample',1:200))
  data &lt;- data.table(cbind(cpgs,samples))
  colnames(data) &lt;- n
  </code></pre>
  <p>I want to run a wilcox.test() on randomly selected columns of this data 1000 times. I've currently implemented this the following way, but it's very slow on large numbers of permutations.</p>
  <pre><code>cases &lt;- paste0('sample',1:10)
  controls &lt;- paste0('sample',30:40)
  data[,wilcox_p:=wilcox.test( as.numeric(.SD[,mget(cases)]), as.numeric(.SD[,mget(controls)]) )$p.value,by=cpg]
  </code></pre>
  <p>Is there a more efficient way to do this? My complete use case, where getCpGSites() is the function described above, is here:</p>
  <pre><code>iterations_vec &lt;- 1:1000
  labels &lt;- paste0('sample',1:200)
  
  permutations &lt;- foreach(i = iterations_vec, .combine='rbind', .multicombine = TRUE ) %dopar% {
      
      case_labels &lt;- sample(labels,num_cases,replace=FALSE)
      control_labels &lt;- labels[!labels %in% case_labels]
      
      signature_cpgs &lt;- getCpGSites(case_labels,control_labels)
      num_signature_cpgs &lt;- length(signature_cpgs)
      
      out &lt;- data.table('gene' = gene,
                        'iteration' = i,
                        'num_signature_cpgs' = num_signature_cpgs)
      return(out)
      
    }
  </code></pre>