title: Apply a calculation to every possible unique subset of a dataframe
body: <p>I'm facing the following problem: I have a <code>dataset</code> with more than <code>50</code> rows and approx <code>100,000</code> columns, all containing <code>TRUE/FALSE</code> values. In this <code>dataset</code>,I want to compute the <code>max colSums</code> for every possible unique subset of <code>50,49,48,..,2 rows</code>, for example I want to compute the maximum column sum of all columns in all subsets of 49 rows .</p>
  
  <p>A brute force approach like the (hasty) one presented below is computationally impossible as for example <code>(50,30)</code> produces <code>4.7129212243e+13</code> unique combinations, so approaches based on actually finding all subsets  (with combn, combnPrim, powerset or expand.grind) should clearly not be used. How could this problem be solved?</p>
  
  <pre><code>dummy&lt;-structure(list(V1 = c(TRUE, TRUE, TRUE, TRUE), V2 = c(FALSE, 
  TRUE, FALSE, FALSE), V3 = c(TRUE, TRUE, FALSE, TRUE), V4 = c(TRUE, 
  FALSE, FALSE, TRUE), V5 = c(TRUE, TRUE, TRUE, TRUE), V6 = c(FALSE, 
  FALSE, FALSE, TRUE), V7 = c(TRUE, TRUE, FALSE, FALSE), V8 = c(TRUE, 
  TRUE, TRUE, TRUE), V9 = c(FALSE, FALSE, FALSE, FALSE), V10 = c(TRUE, 
  TRUE, TRUE, TRUE), V11 = c(TRUE, TRUE, TRUE, TRUE), V12 = c(FALSE, 
  TRUE, TRUE, TRUE), V13 = c(FALSE, TRUE, TRUE, TRUE), V14 = c(FALSE, 
  FALSE, FALSE, FALSE), V15 = c(TRUE, TRUE, TRUE, TRUE), V16 = c(FALSE, 
  FALSE, FALSE, FALSE), V17 = c(FALSE, TRUE, TRUE, FALSE), V18 = c(TRUE, 
  TRUE, TRUE, TRUE), V19 = c(FALSE, FALSE, FALSE, TRUE), V20 = c(TRUE, 
  TRUE, TRUE, TRUE)), .Names = c("V1", "V2", "V3", "V4", "V5", 
  "V6", "V7", "V8", "V9", "V10", "V11", "V12", "V13", "V14", "V15", 
  "V16", "V17", "V18", "V19", "V20"), row.names = c("a", "b", "c", 
  "d"), class = "data.frame")
  a&lt;-combn(4,1)
  b&lt;-combn(4,2)
  c&lt;-combn(4,3)
  
  results&lt;-c()
  
  results[1]&lt;-max(colSums(dummy[b[,1],]),colSums(dummy[b[,2],]),colSums(dummy[b[,3],]),colSums(dummy[b[,4],]),colSums(dummy[b[,5],]),colSums(dummy[b[,6],]))
  
  results[2]&lt;-max(colSums(dummy[c[,1],]),colSums(dummy[c[,2],]),colSums(dummy[c[,3],]),colSums(dummy[c[,4],]))
  
  results[3]&lt;-max(colSums(dummy))
  </code></pre>