Considering a test dataset,
dat=data.frame(name=c('A','A','B','C','C','C'),val=c(1,1,2,2,3,2))
name val
A 1
A 1
B 2
C 2
C 3
C 2
What would be the most efficient way to get this output
name val
A 1
A-1 1
B 2
C 2
C-1 3
C-2 2
So, just marking the duplicates with a custom identifier.
I could think of marking them with an common identifier using paste(dat[which(duplicated(dat$name)),1],"-1",sep=''), but this will just put “-1” in front of all the duplicated ones. I want if the item appears for the 3rd time, mark it with “-2” and so on.
Cheers
Using
make.unique: