| poly_pivot_wider {dunlin} | R Documentation |
Transforming data.frame with multiple Data Column into Wide Format
Description
Transforming data.frame with multiple Data Column into Wide Format
Usage
poly_pivot_wider(
data,
id,
param_from,
value_from,
labels_from = NULL,
drop_na = TRUE,
drop_lvl = FALSE
)
Arguments
data |
( |
id |
( |
param_from |
( |
value_from |
( |
labels_from |
( |
drop_na |
( |
drop_lvl |
( |
Details
This function is adapted to cases where the data are distributed in several columns while the name of the
parameter is in one. Typical example is adsub where numeric data are stored in AVAL while categorical data are
in AVALC.
Value
list of data.frame in a wide format with label attribute attached to each columns.
Examples
test_data <- data.frame(
the_obs = c("A", "A", "A", "B", "B", "B", "C", "D"),
the_obs2 = c("Ax", "Ax", "Ax", "Bx", "Bx", "Bx", "Cx", "Dx"),
the_param = c("weight", "height", "gender", "weight", "gender", "height", "height", "other"),
the_label = c(
"Weight (Kg)", "Height (cm)", "Gender", "Weight (Kg)",
"Gender", "Height (cm)", "Height (cm)", "Pre-condition"
),
the_val = c(65, 165, NA, 66, NA, 166, 155, NA),
the_val2 = c(65, 165, "M", 66, "F", 166, 155, TRUE)
)
x <- poly_pivot_wider(
test_data,
c("the_obs", "the_obs2"),
"the_param",
c("the_val", "the_val2"),
"the_label"
)
x
Reduce(function(u, v) merge(u, v, all = TRUE), x)