Skip to contents

Rename duplicates by adding a suffix

Usage

rename_duplicates(x, sep = "_", type = "alphabet", all = TRUE)

Arguments

x

A vector

sep

Specify the separator (delimiter) to use before the suffix

type

Use letters (alphabet) or numbers to create the suffix

all

Add the suffix to elements of the duplicated value, including the first instance (all=TRUE), or just to the subsequent instances

Examples

x<-c(404, 405,406, 407, 408, 408 ,408, 408,409 ,409,410,411)
rename_duplicates(x)
#>  [1] "404"   "405"   "406"   "407"   "408_a" "408_b" "408_c" "408_d" "409_a"
#> [10] "409_b" "410"   "411"  
rename_duplicates(x,all=FALSE)
#>  [1] "404"   "405"   "406"   "407"   "408"   "408_b" "408_c" "408_d" "409"  
#> [10] "409_b" "410"   "411"  
rename_duplicates(x,type="numeric")
#>  [1] "404"   "405"   "406"   "407"   "408_1" "408_2" "408_3" "408_4" "409_1"
#> [10] "409_2" "410"   "411"  
rename_duplicates(x,type="numeric",all=FALSE)
#>  [1] "404"   "405"   "406"   "407"   "408"   "408_2" "408_3" "408_4" "409"  
#> [10] "409_2" "410"   "411"