Make Elements of a Vector Unique in R Programming – make.unique() Function
Last Updated :
10 Aug, 2021
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: Separator to be used
Example 1:
Python3
make.unique(c( "a" , "a" , "a" ))
make.unique(c( "a" , "b" , "c" , "a" ))
make.unique(c( "1" , "2" , "3" , "1" , "2" ))
|
Output:
[1] "a" "a.1" "a.2"
[1] "a" "b" "c" "a.1"
[1] "1" "2" "3" "1.1" "2.1"
Example 2:
Python3
make.unique(c( "a" , "a" , "a" ), sep = "_" )
make.unique(c( "a" , "a" , "a" ), sep = "@" )
make.unique(c( "a" , "a" , "a" ), sep = "$" )
|
Output:
[1] "a" "a_1" "a_2"
[1] "a" "a@1" "a@2"
[1] "a" "a$1" "a$2"
Share your thoughts in the comments
Please Login to comment...