I have the following dataset:
dataset <- data.frame(id = c("A","A","A","A","B","B","B,"B"),
value = c(1,1,2,3,5,6,6,7))
For every id that is duplicated, I want to flag the row where it happens, and this flag should be the same length of the dataframe source. This is the expected result:
id value flag
A 1 1
A 1 1
A 2 0
A 3 0
B 5 0
B 6 1
B 6 1
B 7 0
Is there a way where I don't have to use a for loop? Any help will be greatly appreciated.