make.names(names, unique = FALSE, allow_ = TRUE)
TRUE
, the resulting elements are
unique. This may be desired for, e.g., column names.names
with each changed to
a syntactically valid name, in the current locale's encoding.".2way"
are not valid, and neither
are the reserved words. The definition of a letter depends on the current locale, but
only ASCII digits are considered to be digits. 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
.make.unique
,
names
,
character
,
data.frame
.make.names(c("a and b", "a-and-b"), unique = TRUE)
# "a.and.b" "a.and.b.1"
make.names(c("a and b", "a_and_b"), unique = TRUE)
# "a.and.b" "a_and_b"
make.names(c("a and b", "a_and_b"), unique = TRUE, allow_ = FALSE)
# "a.and.b" "a.and.b.1"
make.names(c("", "X"), unique = TRUE)
# "X.1" "X" currently; R up to 3.0.2 gave "X" "X.1"
state.name[make.names(state.name) != state.name] # those 10 with a space
Run the code above in your browser using DataLab