stretch {cheese} | R Documentation |
Span keys and values across the columns
Description
Pivot one or more values across the columns by one or more keys
Usage
stretch(
data,
key,
value,
sep = "_"
)
Arguments
data |
A |
key |
A vector of quoted/unquoted columns, positions, and/or |
value |
A vector of quoted/unquoted columns, positions, and/or |
sep |
String to separate keys/values by in the resulting column names. Defaults to |
Details
In the case of multiple value
's, the labels are always appended to the end of the resulting columns.
Value
A tibble::tibble
Author(s)
Alex Zajichek
Examples
#Make a summary table
set.seed(123)
data <-
heart_disease %>%
dplyr::group_by(
Sex,
BloodSugar,
HeartDisease
) %>%
dplyr::summarise(
Mean = mean(Age),
SD = sd(Age),
.groups = "drop"
) %>%
dplyr::mutate(
Random =
rbinom(nrow(.), size = 1, prob = .5) %>%
factor
)
data %>%
stretch(
key = c(BloodSugar, HeartDisease),
value = c(Mean, SD, Random)
)
data %>%
stretch(
key = where(is.factor),
value = where(is.numeric)
)
data %>%
stretch(
key = c(where(is.factor), where(is.logical)),
value = where(is.numeric)
)
[Package cheese version 0.1.2 Index]