Learn R Programming

uniqtag (version 1.0.1)

make_unique: Make character strings unique.

Description

Append sequence numbers to duplicate elements to make all elements of a character vector unique.

Usage

make_unique(xs, sep = "-")

make_unique_duplicates(xs, sep = "-")

make_unique_all(xs, sep = "-")

make_unique_all_or_none(xs, sep = "-")

Arguments

xs

a character vector

sep

a character string used to separate a duplicate string from its sequence number

Functions

  • make_unique: Append a sequence number to duplicated elements, including the first occurrence.

  • make_unique_duplicates: Append a sequence number to duplicated elements, except the first occurrence.

    This function behaves similarly to make.unique

  • make_unique_all: Append a sequence number to every element.

  • make_unique_all_or_none: Append a sequence number to every element or no elements.

    Return xs unchanged if the elements of the character vector xs are already unique. Otherwise append a sequence number to every element.

See Also

make.unique

Examples

Run this code
# NOT RUN {
abcb <- c("a", "b", "c", "b")
make_unique(abcb)
make_unique_duplicates(abcb)
make_unique_all(abcb)
make_unique_all_or_none(abcb)
make_unique_all_or_none(c("a", "b", "c"))
x <- make_unique(abbreviate(state.name, 3, strict = TRUE))
x[grep("-", x)]
# }

Run the code above in your browser using DataLab