strUniquefy: Uniquefy a character vector

Description Usage Arguments Details Value Examples

View source: R/str_uniquefy.R

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

1
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.

Details

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

Value

returns a character vector

Examples

1
2
3
4
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"))

spsUtil documentation built on Oct. 31, 2021, 1:06 a.m.