clean_names | R Documentation |
Resulting names are unique and consist only of the _
character, numbers, and letters.
Capitalization preferences can be specified using the case
parameter.
Accented characters are transliterated to ASCII. For example, an "o" with a German umlaut over it becomes "o", and the Spanish character "enye" becomes "n".
This function takes and returns a data.frame, for ease of piping with
`%>%`
. For the underlying function that works on a character vector
of names, see make_clean_names
. clean_names
relies on the versatile function to_any_case
, which
accepts many arguments. See that function's documentation for ideas on getting
the most out of clean_names
. A few examples are included below.
A common issue is that the micro/mu symbol is replaced by "m" instead of "u".
The replacement with "m" is more correct when doing Greek-to-ASCII
transliteration but less correct when doing scientific data-to-ASCII
transliteration. A warning will be generated if the "m" replacement occurs.
To replace with "u", please add the argument replace=janitor:::mu_to_u
which is a character vector mapping all known mu or micro Unicode code points
(characters) to "u".
clean_names(dat, ...)
## Default S3 method:
clean_names(dat, ...)
## S3 method for class 'sf'
clean_names(dat, ...)
## S3 method for class 'tbl_graph'
clean_names(dat, ...)
## S3 method for class 'tbl_lazy'
clean_names(dat, ...)
dat |
the input data.frame. |
... |
Arguments passed on to
|
clean_names()
is intended to be used on data.frames
and data.frame
-like objects. For this reason there are methods to
support using clean_names()
on sf
and tbl_graph
(from
tidygraph
) objects as well as on database connections through
dbplyr
. For cleaning other named objects like named lists
and vectors, use make_clean_names()
.
Returns the data.frame with clean names.
Other Set names:
find_header()
,
mu_to_u
,
row_to_names()
# --- Simple Usage ---
x <- data.frame(caseID = 1, DOB = 2, Other = 3)
clean_names(x)
# or pipe in the input data.frame:
x %>%
clean_names()
# if you prefer camelCase variable names:
x %>%
clean_names(., "lower_camel")
# (not run) run clean_names after reading in a spreadsheet:
# library(readxl)
# read_excel("messy_excel_file.xlsx") %>%
# clean_names()
# --- Taking advantage of the underlying snakecase::to_any_case arguments ---
# Restore column names to Title Case, e.g., for plotting
mtcars %>%
clean_names(case = "title")
# Tell clean_names to leave certain abbreviations untouched:
x %>%
clean_names(case = "upper_camel", abbreviations = c("ID", "DOB"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.