This function checks for duplicated elements in a vector. If duplicated elements are found, it appends an underscore and a sequence number to each occurrence of the duplicated element.

name_duplicated(x)

Arguments

x

A character vector.

Value

A character vector where duplicated names are made unique by appending a sequence number.

Examples

vec <- c("apple", "orange", "apple", "banana", "orange")
name_duplicated(vec)
#> [1] "apple_1"  "orange_1" "apple_2"  "banana"   "orange_2"