| infer_spec | R Documentation |
Heuristics, in order: all-missing columns are empty; trial and EDC key
names (USUBJID, SUBJID, SITEID, STUDYID, RANDNO, ...) are id;
identifier-like
names with near-unique values (or code-like values such as AB123) are
id; a single value with no missing cells is constant; mostly-date
columns are date; mostly-numeric columns are numeric, or categorical
if they take few distinct values (coded 0/1/2 fields); remaining character
columns are categorical when the label set is small and text otherwise.
infer_spec(
src,
id = NULL,
text = NULL,
roles = NULL,
id_pattern = NULL,
text_pattern = NULL,
max_levels = 10,
max_cat_levels = 60,
warn_unknown = TRUE
)
src |
A |
id, text |
Column names (internal or on-disk, case-insensitive) to
force to |
roles |
Named character vector of further role overrides. |
id_pattern, text_pattern |
Regular expressions on column names, e.g.
|
max_levels |
Numeric columns with at most this many distinct values are treated as categorical. |
max_cat_levels |
Character columns with at most this many labels (and at most 10% of the observed rows) are categorical, otherwise text. |
warn_unknown |
Warn about override names that match no column. |
A data.frame, one row per column: column, orig_name, role,
n_obs, n_unique, miss_frac, num_frac, date_frac, reason.
df <- data.frame(id = sprintf("AB%03d", 1:60), value = 1:60,
code = rep(c(0, 1, NA), 20), group = rep(c("A", "B"), 30))
path <- file.path(tempdir(), "infer_spec.csv")
utils::write.csv(df, path, row.names = FALSE, na = "")
src <- read_source(path)
spec <- infer_spec(src, id = "id", roles = c(code = "categorical"))
spec[, c("column", "role", "reason")]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.