I have a dataframe where a column has duplicate values like
employee <- data.frame(name = c('John', 'Joe', 'Mat', 'John', 'Joe'),
salary = c(1500, 2000, 1700, 1210, 2100),
startdate = c('2012-05-10', '2015-02-17',
'2014-09-11', '2011-11-23', '2010-10-27'))
I can get the unique elements in column 1 by
unique(employee$name)
However, I want to make each items in the name
column unique. If something appears second time append _1 to it. If it appears again append _2 to it. So, in the employee dataframe, I want to change the second column to
John
Joe
Mat
John_1
Joe_1
Is there a way except looping over it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…