make.unique: Make character strings unique

View source: R/data_frames.R View source: R/data_frames.R

make.uniqueR Documentation

Make character strings unique

Description

Makes the elements of a character vector unique by appending sequence numbers to duplicates.

Usage

make.unique(names, sep = ".", start = 2)

Arguments

names

a character vector

sep

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

Details

The algorithm used by make.unique has the property that make.unique(c(A,B)) = make.unique(c(make.unique(A),B)).

In other words, you can append one string at a time to a vector, making it unique each time, and get the same result as applying make.unique to all of the strings at once.

If character vector A is already unique, then make.unique(c(A,B)) preserves A.

Value

a character vector of same length as names with duplicates changed.

Author(s)

Thomas P Minka

See Also

make.names

Examples


make.unique(c("a","a","a"))
make.unique(c(make.unique(c("a","a")),"a"))

make.unique(c("a","a","a.2","a"))
make.unique(c(make.unique(c("a","a")),"a.2","a"))

rbind(data.frame(x=1),data.frame(x=2),data.frame(x=3))
rbind(rbind(data.frame(x=1),data.frame(x=2)),data.frame(x=3))


paulemms/datamining documentation built on March 1, 2023, 4:01 p.m.