replace any(duplicated(...)) by faster anyDuplicated