make.names {base} | R Documentation |
Make syntactically valid names out of character vectors.
make.names(names, unique = FALSE)
names |
character vector to be coerced to syntactically valid names. This is coerced to character if necessary. |
unique |
logical; if TRUE , the resulting elements are
unique. This may be desired for, e.g., column names. |
A syntactically valid name consists of letters, numbers and the dot or
underline characters and starts with a letter or the dot not followed
by a number. Names such as ".2way"
are not valid, and neither
are the reserved words.
The character "X"
is prepended if necessary.
All invalid characters are translated to "."
. A missing value
is translated to "NA"
. Names which match R keywords have a dot
appended to them. Duplicated values are altered by
make.unique
.
A character vector of same length as names
with each changed to
a syntactically valid name.
make.unique
,
names
,
character
,
data.frame
.
make.names(c("a and b", "a_and_b"), unique=TRUE) # "a.and.b" "a.and.b.1" data(state) state.name[make.names(state.name) != state.name] # those 10 with a space