Finds every column in data that inherits from npsych_scores,
standardizes it via std(), and adds the result as a new column with a
"z_" prefix (e.g., MOCATOTS → z_MOCATOTS).
Each score class can use a different method/version combination.
Classes not mentioned in methods fall back to their registered
defaults (see set_std_defaults()).
Usage
std_data(
data,
...,
methods = list(),
prefix_std = "z_",
prefix_raw = NULL,
.cols = NULL
)Arguments
- data
A
data.frameordata.tablecontaining one or morenpsych_scorescolumns.- ...
Named covariates shared across all score columns (e.g.,
age,sex,educ). These are passed to everystd()call and must be supplied explicitly. Values can be bare column names referencing columns indata(e.g.,age = age) or explicit vectors (e.g.,age = c(72, 65, 80)).- methods
An optional named list keyed by
npsych_scoresclass name (not column name). Each element is a named character vector of the formc(method = "...", version = "..."). Both elements are optional within each entry; omitted elements resolve to the registered default. Classes not listed use their defaults.- prefix_std
A single string prepended to each score column name to form the new column name. Defaults to
"z_".- prefix_raw
Optional; if character string, used as prefix for scores that are standardized. This enables you to obtain pairs of scores, for example
raw_MOCATOTSandz_MOCATOTSfor bookkeeping- .cols
An optional character vector of
npsych_scorescolumn names to standardize. WhenNULL(the default), allnpsych_scorescolumns are processed.
Value
The input data with additional standardized score columns
appended. The original columns are left unchanged (unless prefix_raw
is specified, in which case they are renamed with that prefix). The
return type matches the input type (data.frame or data.table).
Each standardized column is an std_npsych_scores object with S7
properties @method, @version, @description, and
@scores_subclass. Use methods_from_std_data() to extract the
method and version from all standardized columns at once.
The returned data frame carries two attributes:
prefix_stdThe prefix used for standardized columns (default
"z_").prefix_rawThe prefix used for raw score columns, or
NULLifprefix_rawwas not specified.
See also
std() for standardizing a single npsych_scores vector.
Examples
if (FALSE) { # \dontrun{
# Bare column names — evaluated against data
std_data(my_data, age = age, sex = sex, educ = educ)
# Explicit vectors work too
std_data(my_data, age = my_data$age, sex = my_data$sex, educ = my_data$educ)
# Override method/version for specific test classes
std_data(
my_data,
methods = list(
MOCATOTS = list(method = "norms", version = "nacc"),
ANIMALS = list(method = "regression", version = "updated_2025.06")
),
age = age, sex = sex, educ = educ
)
} # }