stretch | R Documentation |
Pivot one or more values across the columns by one or more keys
stretch( data, key, value, sep = "_" )
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 |
In the case of multiple value
's, the labels are always appended to the end of the resulting columns.
A tibble::tibble
Alex Zajichek
#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) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.