So I have this column in a data frame consisting of species names:
species
Dasyatis pastinaca
Amblyraja radiata
Raja montagui
Raja montagui
Dasyatis pastinaca
Himantura imbricata
Mobula thurstoni
Raja montagui
Mobula thurstoni
Dalatias licha
Many of them are repeated and what I'm trying to do is, for every set of repeated names, add a suffix which is their id number. Basically this is the output I'm looking for for the column:
new_species
Dasyatis pastinaca_01
Amblyraja radiata_01
Raja montagui_01
Raja montagui_02
Dasyatis pastinaca_02
Himantura imbricata_01
Mobula thurstoni_01
Raja montagui_03
Mobula thurstoni_02
Dalatias licha_01
I've tried creating a new column (new_species) from the original column (species), followed by two for loops:
df<- df[order(df$species),]
df$new_species=df$species
for (i in unique(df$new_species)){
for (j in df[df$species==i,]$new_species){
paste0(j,seq(1,length(df[taxon1df9$new_species==j,]$new_species)))
}
}