The R Project SVN R

Rev

Rev 61150 | Rev 76240 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/base/man/make.unique.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2008 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
24855 ripley 6
\name{make.unique}
56186 murdoch 7
\alias{make.unique}
24855 ripley 8
\title{Make Character Strings Unique}
9
\description{
10
  Makes the elements of a character vector unique by
11
  appending sequence numbers to duplicates.
12
}
13
\usage{
25360 ripley 14
make.unique(names, sep = ".")
24855 ripley 15
}
16
\arguments{
17
  \item{names}{a character vector}
18
  \item{sep}{a character string used to separate a duplicate name from
19
    its sequence number.}
20
}
21
\value{
45778 ripley 22
  A character vector of same length as \code{names} with duplicates
23
  changed, in the current locale's encoding.
24855 ripley 24
}
25
\details{
26
  The algorithm used by \code{make.unique} has the property that
27
  \code{make.unique(c(A, B)) == make.unique(c(make.unique(A), B))}.
28
 
29
  In other words, you can append one string at a time to a vector,
30
  making it unique each time, and get the same result as applying
31
  \code{make.unique} to all of the strings at once.
61433 ripley 32
 
24855 ripley 33
  If character vector \code{A} is already unique, then
34
  \code{make.unique(c(A, B))} preserves \code{A}.
35
}
45778 ripley 36
\author{Thomas P. Minka}
24855 ripley 37
\seealso{
38
  \code{\link{make.names}}
39
}
40
\examples{
41
make.unique(c("a", "a", "a"))
42
make.unique(c(make.unique(c("a", "a")), "a"))
43
 
44
make.unique(c("a", "a", "a.2", "a"))
45
make.unique(c(make.unique(c("a", "a")), "a.2", "a"))
46
 
61150 ripley 47
rbind(data.frame(x = 1), data.frame(x = 2), data.frame(x = 3))
48
rbind(rbind(data.frame(x = 1), data.frame(x = 2)), data.frame(x = 3))
24855 ripley 49
}
50
\keyword{character}