I'm working with a dataframe that has a column (ID) contains IDs for a bunch of projects. Unfortunately, some of these IDs are duplicated (but the projects are not).
I'm looking to make the IDs for the duplicate values unique by adding (.a, .b, .c, etc) to the end of them. I can't use numbers (or the make.unique function) because the IDs have numbers at the end which could be confusing.
I currently have the below but it gives every ID an appended letter. Is there anything I can add so that it only impacts the duplicated IDs?
df$ID <- ave(df$ID, df$ID, FUN = function(i) paste0(i, '.', letters[1:20]))
Thanks for any help!
We may need a condition that checks the length
before paste
ing
ave(df$ID, df$ID, FUN = function(i)
if(length(i) > 1) {
i[-1] <- paste0(i[-1], '.', letters[seq(length(i[-1]))]); i} else i)