| validate_cp_data | R Documentation |
This function performs validation checks on cross-price demand data and applies filtering if specified. It ensures the data meets the requirements for analysis by checking for required columns (after optional column renaming), filtering by target type if needed, and confirming ID column presence when required.
validate_cp_data(
data,
x_var = "x",
y_var = "y",
id_var = "id",
group_var = "group",
target_var = "target",
required_cols = c("x", "y"),
filter_target = TRUE,
target_level = "alt",
require_id = FALSE
)
data |
A data frame containing cross-price demand data. |
x_var |
Character string; name of the price column. Default is |
y_var |
Character string; name of the consumption column. Default is |
id_var |
Character string; name of the subject identifier column.
Default is |
group_var |
Character string; name of the group column. Default is
|
target_var |
Character string; name of the target indicator column.
Default is |
required_cols |
Character vector of canonical column names to check after
renaming. Default is |
filter_target |
Logical; if TRUE and data contains a |
target_level |
Character string; the value of the |
require_id |
Logical; if TRUE, validates that an |
Column renaming uses a collision-safe approach: if a non-default *_var
mapping is requested but the canonical target name already exists as a
different column in data, the function stops with an informative error
rather than silently overwriting data. After normalization, $data on
returned objects always uses canonical names (x, y, id, group,
target), which is required for S3 methods to work correctly.
A validated (and potentially filtered) data frame with canonical column names.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.