Make Elements of a Vector Unique in R Programming – make.unique() Function

make.unique() function in R Language is used to return elements of a vector with unique names by appending sequence numbers to duplicates.

Syntax: make.unique(names, sep)

Parameters:
names: Character vector with duplicate names
sep: Separater to be used

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to make unique vectors
  
# Calling make.unique() Function
make.unique(c("a", "a", "a"))
make.unique(c("a", "b", "c", "a"))
make.unique(c("1", "2", "3", "1", "2"))

chevron_right


Output:

[1] "a"   "a.1" "a.2"
[1] "a"   "b"   "c"   "a.1"
[1] "1"   "2"   "3"   "1.1" "2.1"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to make unique vectors
  
# Calling make.unique() Function
# with different separater values
make.unique(c("a", "a", "a"), sep = "_")
make.unique(c("a", "a", "a"), sep = "@")
make.unique(c("a", "a", "a"), sep = "$")

chevron_right


Output:

[1] "a"   "a_1" "a_2"
[1] "a"   "a@1" "a@2"
[1] "a"   "a$1" "a$2"
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.