C1 C2
------
a 11
a 2
a 2
b 2
b 34
c 2
c 4
c 1
d 4
how can i get index of a groupname first occurence
for example: in column A first occurence of 'b' index is 4 like that i need to get all indexes of first occurence of group
With data.table
package, you can get it with .I
:
as.data.table(dtt)[, .(index = .I[1]), by = .(C1)]
# C1 index
# 1: a 1
# 2: b 4
# 3: c 6
# 4: d 9
If only indices are need:
which(!duplicated(dtt$C1))
[1] 1 4 6 9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With