R/f_spread.R

Defines functions f_spread

#https://community.rstudio.com/t/spread-with-multiple-value-columns/5378
f_spread <- function(df, key, value) {
  # quote key
  keyq <- rlang::enquo(key)
  # break value vector into quotes
  valueq <- rlang::enquo(value)
  s <- rlang::quos(!!valueq)
  df %>% gather(variable, value, !!!s) %>%
    unite(temp, !!keyq, variable) %>%
    spread(temp, value)
}
ManuelaRunge/ranalysis documentation built on Dec. 7, 2024, 5:01 a.m.