title: Group by and keep columns with matching pattern
body: <p>I'm trying to figure out how to group by one variable and keep all other variables that have the same variation pattern. Here's a sample df where gp is my grouping variable:</p>
  
  <pre><code>   V1 V2 V3 V4 V5 V6 gp
  1  0  1  0  0  0  0  x
  2  0  0  0  0  1  0  x
  3  1  0  1  0  1  1  y
  4  0  0  0  0  0  1  x
  </code></pre>
  
  <p>What I'd like to end up with is:</p>
  
  <pre><code>  V1 V3 gp
  1  0  0  x
  2  0  0  x
  3  1  1  y
  4  0  0  x
  </code></pre>
  
  <p>I've tried a bunch of things, but nothing that get's me anywhere close to something useful. My real data will be much larger, but I figure this is a good place to start. In this case, I could do something numeric, but my 'real data' are genomic data, and thus not as easily added as 0s and 1s.</p>
  
  <p>data: </p>
  
  <pre><code>structure(list(V1 = c(0L, 0L, 1L, 0L), V2 = c(1L, 0L, 0L, 0L), 
      V3 = c(0L, 0L, 1L, 0L), V4 = c(0L, 0L, 0L, 0L), V5 = c(0L, 
      1L, 1L, 0L), V6 = c(0L, 0L, 1L, 1L), gp = structure(c(1L, 
      1L, 2L, 1L), .Label = c("x", "y"), class = "factor")), class = "data.frame", row.names = c(NA, 
  -4L))
  </code></pre>