How to remove successive duplicate rows based on first columnv1
?
v1 v2
1 A
1 A
2 B
3 B
1 A
1 A
2 A
2 B
Desired Output:
v1 v2
1 A
2 B
3 B
1 A
2 A
How to remove successive duplicate rows based on first columnv1
?
v1 v2
1 A
1 A
2 B
3 B
1 A
1 A
2 A
2 B
Desired Output:
v1 v2
1 A
2 B
3 B
1 A
2 A
Here's a way with rle
in base R -
x <- c(1,1,2,3,1,1,2,2)
ind <- with(rle(x), sequence(lengths) == 1)
x[ind]
[1] 1 2 3 1 2
Another way would be by checking lag values -
ind <- c(TRUE, x[-length(x)] != x[-1])
x[ind]
[1] 1 2 3 1 2