Learn R Programming

spsUtil (version 0.2.2)

strUniquefy: Uniquefy a character vector

Description

Fix duplicated values in a character vector, useful in column names and some ID structures that requires unique identifiers. If any duplicated string is found in the vector, a numeric index will be added after the these strings.

Usage

strUniquefy(x, sep_b = "_", sep_a = "", mark_first = TRUE)

Arguments

x

character vector

sep_b

string, separator before the number index

sep_a

string, separator after the number index

mark_first

bool, if duplicated values are found, do you want to add the numeric index starting from the first copy? FALSE means starting from the second copy.

Value

returns a character vector

Details

The input can also be a numeric vector, but the return will always be character.

Examples

Run this code
# NOT RUN {
strUniquefy(c(1,1,1,2,3))
strUniquefy(c(1,1,1,2,3), mark_first = FALSE)
strUniquefy(c(1,1,1,2,3), sep_b = "(", sep_a = ")")
strUniquefy(c("a","b","c","a","d","b"))
# }

Run the code above in your browser using DataLab