make.names {base}R Documentation

Make Syntactically Valid Names Out of Strings

Description

Make syntactically valid names out of character strings.

Usage

make.names(names, unique = FALSE)

Arguments

names character (vector) to be coerced to syntactically valid names.
unique logical; if TRUE, the resulting strings are unique. This may be desired for, e.g., column names.

Details

A syntactically valid name consists of letters, numbers, and the dot character and starts with a letter or the dot.

All invalid characters are translated to ".".

Value

A character vector of same length as names with each changed to a syntactically valid name.

See Also

names, character, data.frame.

Examples

make.names(c("a and b", "a_and_b"), unique=TRUE)#-> "a.and.b"  "a.and.b1"

all(make.names(letters) == letters)# TRUE

data(state)
state.name[make.names(state.name) != state.name]# those 10 with a space