So, I have a vector, species, containing names of different species. Normally, these names are made up of the regular two words, however, ocasionally, some elements of the vector also include the sub-species (i.e. the third word), or sometimes even other alpha-numeric characters.
species<-c("Abia americana", "Abia americana","Abia americana primaria","Abia aurulenta", "Leptomyrmex fragilis","Leptomyrmex fragilis sapana", "Parasinilabeo longiventralis laran", "Rhizorhagium arenosum","Rhizorhagium arenosum","Rhizorhagium arenosum COMPLX. 18","Stelis phaeoptera phaeo")
I want to remove the last word or words (or expressions, as in the case of Rhizorhagium arenosum COMPLX. 18) from each string, but only if the entirety of the rest of the string has at least one duplicate in my species vector.
Basically, my output would be something like this:
c("Abia americana", "Abia americana","Abia americana","Abia aurulenta", "Leptomyrmex fragilis","Leptomyrmex fragilis", "Parasinilabeo longiventralis laran", "Rhizorhagium arenosum","Rhizorhagium arenosum","Rhizorhagium arenosum","Stelis phaeoptera phaeo")
Thank you in advance for any answers.