| clean_table | R Documentation |
Real custodian tables arrive with column names that are not valid R
names ("Yield (t/ha)", "Site Name"), leading or trailing
whitespace in names and factor / character values, and the
occasional near-duplicate label ("north" vs "North" vs
" north"). clean_table() legalises names and trims whitespace, and
reports each fix. Near-duplicate labels are only reported, since merging
labels that look alike is a judgement call; conform_table() makes it.
clean_table(df, clean = c("auto", "report", "off"), quiet = FALSE)
df |
A data frame. |
clean |
One of |
quiet |
Logical. When |
The corrections are returned alongside the cleaned data, so mask()
records them in the recipe and apply_recipe() re-applies the same
cleaning to the original.
Two input columns with the same name are refused with a
masque_duplicate_names_refusal error: the recipe records renamed
columns by their original name, so the two could not be told apart on
the round trip. Rename them first.
An object of class masque_cleaning: a list with
data - the cleaned (or, under report / off,
unchanged) data.table;
name_map - named character original -> clean for every
column whose name changed (empty if none);
level_fixes - named list, one entry per column whose
values were trimmed, each a named character original -> clean;
near_duplicates - a data.table of report-only label pairs
(col, a, b, kind) that look like typos but were left
untouched. Labels that differ only inside a run of digits
("G01" and "G02", "Plot12" and "Plot13") are different
codes and are not listed. The printed report shows the first 20
pairs and the count, and a recipe keeps the same;
mode - the clean mode applied.
mask(), propose_roles().
df <- data.frame(
`Site Name` = c("north ", "north", "South"),
`Yield (t/ha)` = c(3.1, 2.9, 5.0),
check.names = FALSE
)
cl <- clean_table(df, quiet = TRUE)
names(cl$data)
cl$near_duplicates
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.