Dear R Users,
I want to keep only the very first sequence for a given number.
Example Data
For each unique values in the column, here, they are 5,1,2 and 3. I want to keep only the sequence which appeared for the first time.
For example, I want to keep the first 3 rows for 5. The reappearances are to be discarded. e.g: 5 appears in row 8 and 9 again, which will be thrown away. Same for the rest of the values.
Many Thanks.
I want to keep only the very first sequence for a given number.
Example Data
Code:
d.f<-data.frame(var1=c(5,5,5,1,1,2,2,5,5,3,1,1,1))
>d.f
var1
1 5
2 5
3 5
4 1
5 1
6 2
7 2
8 5
9 5
10 3
11 1
12 1
13 1
# Unique Values
> unique(d.f)
var1
1 5
4 1
6 2
10 3
For example, I want to keep the first 3 rows for 5. The reappearances are to be discarded. e.g: 5 appears in row 8 and 9 again, which will be thrown away. Same for the rest of the values.
Code:
# the desired output will look like this
var1
1 5
2 5
3 5
4 1
5 1
6 2
7 2
10 3