Assume I have a data frame as this:

```
my_df<- data.frame(mat1=c(1,2,2,2,1,2,2),
               mat2=c(5,4,3,1,5,4,4),
               mat3=c(4,1,6,9,4,1,1),
               mat4=c(1,2,6,9,1,2,2))

```

I actually know how to identify the repeats, which gives me the follwoing:

```
   mat1 mat2 mat3 mat4 Repeat
1    1    5    4    1   TRUE
2    2    4    1    2   TRUE
3    2    3    6    6  FALSE
4    2    1    9    9  FALSE
5    1    5    4    1   TRUE
6    2    4    1    2   TRUE
7    2    4    1    2   TRUE

```

I want to bucket the similar pattern, to generate the classes as follows:

```
  mat1 mat2 mat3 mat4 Repeat repeat_class
1    1    5    4    1   TRUE            1
2    2    4    1    2   TRUE            2
3    2    3    6    6  FALSE            0
4    2    1    9    9  FALSE            0
5    1    5    4    1   TRUE            1
6    2    4    1    2   TRUE            2
7    2    4    1    2   TRUE            2

```

where, repeat\_class=0 shows non-repeated data records,repeat\_class=1,2,etc identifies the similar paterns found in the data records. 

I can do it in for loops, but for a large dataset it is just taking too long. I'm wondering if there is any faster way to do that in R?