I was looking for duplicated IDs (string) in my dataframe, and if it's true, change for a sequence.
I tried using the duplicate(x)
method but does not seem to find anyone (there are duplicates in my csv). I also saw this web in S.O: Find duplicate values in R and nothing happened apparently.
This is my code so far:
library(stringr)
if (duplicated(census$CS_ID)==TRUE){
new_CS <- sprintf("CS%d",seq(1:length(census$CS_ID)-1))
census$CS_ID <- str_replace_all(census$CS_ID, "^.*$", new_CS)
}
I think the main problem is the ==TRUE condition, where maybe it should be if there is any TRUE in the duplicate()
clause and not such a whole.
This is a sample of my csv
CS_ID (str)
CS620
CS621
CS622
CS624
CS624
CS625
CS626
CS627
Thank you for any help! =)