Finding unique columns
<p>Please help. I have a data frame like the following:</p>

<pre><code>df &lt;- data.frame("G"=c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7), 
                  "C"=c(1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,1,0),
                "SKU"=c("a","b","c","a","c","d","a","c","d","a","b","c","a","b","c","b","c","d","a","b","c"))
df
 G C SKU
 1 1   a
 1 0   b
 1 0   c
 2 0   a
 2 1   c
 2 0   d
 3 1   a
 3 0   c
 3 0   d
 4 0   a
 4 1   b
 4 0   c
 5 1   a
 5 0   b
 5 0   c
 6 0   b
 6 1   c
 6 0   d
 7 0   a
 7 1   b
 7 0   c 
</code></pre>

<p>I want to find unique "blocks" in this data frame. For example, here we have three blocks: (a,b,c) , (a,c,d) and (b,c,d). I want to create table with these unique blocks, and to sum variable "C" in all "G" for each SKU in certain block. And finally get data frame like this:</p>

<pre><code>     New_G SKU New_C
 1       1   a     2
 2       1   b     2
 3       1   c     0
 4       2   a     1
 5       2   c     1
 6       2   d     0
 7       3   b     0
 8       3   c     1
 9       3   d     0
</code></pre>

<p>As I said, here three unique blocks, New_G - identificator of every block, and New_C - the sum of "C" for each SKU that in certain block. (For example, see the first row. SKU = "a", NEW_C = 2  -  it means that in the old data frame SKU "a" while being in the block (a,b,c) has variable "C" = 1 two times) (Another example: see the forth row. Again SKU = "a", but NEW_C = 1 - it means that in the old data frame SKU "a" while being in the block (a,c,d) has variable "C" = 1 once)</p>

<p>If my question is not clear let me now, please. </p>