This is my first post and I'm new to programming and R. 

I'm trying to create a new column to mark or flag sequentially duplicated values in a separate column. 

df <- c(2,2,2,2,3,4,3,4,3,4,2,3,7,7,7)) 

Using the duplicated function returns the following:

data.frame(value = df, flag = duplicated(df))

```
   value  flag  
1      2  FALSE  
2      2  TRUE  
3      2  TRUE  
4      2  TRUE  
5      3  FALSE  
6      4  FALSE  
7      3  TRUE  
8      4  TRUE  
9      3  TRUE  
10     4  TRUE  
11     2  TRUE  
12     3  TRUE  
13     7  FALSE  
14     7  TRUE  
15     7  TRUE   

```

What I'd like is:

```
   value  flag  
1      2  TRUE  
2      2  TRUE  
3      2  TRUE  
4      2  TRUE  
5      3  FALSE  
6      4  FALSE  
7      3  FALSE  
8      4  FALSE  
9      3  FALSE  
10     4  FALSE  
11     2  FALSE  
12     3  FALSE  
13     7  TRUE    
14     7  TRUE    
15     7  TRUE     

```

My data set has over 2 million observations, so ideally the solution would be efficient.

Thank you ,
John