spread_multi: Spread multiple columns simultaneously.

Description Usage Arguments Examples

Description

spread_multi works simililarly to tidyr::spread but allows for multiple value columns to be passed to the ellipsis (...) argument which are spread simultaneously

Usage

1
spread_multi(.data, .key, ..., sep = "_")

Arguments

.data

a data.frame to be spread

.key

the key column which will be spread across the columns of the resulting data frame

...

the value columns to be spread. All column naming conventions that can be used with dplyr::select should behave well with spread_multi

sep

the seperator to create column names of the form '<key_name><sep><key_value>'

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
df <- data_frame(
  month = rep(1:3,2),
  student = rep(c("Amy", "Bob"), each=3),
  x = c(9, 7, 6, 8, 6, 9),
  y = c(6, 7, 8, 5, 6, 7),
  z = c(10, 5, 3, 2, 1, -1)
)

df %>%
  spread_multi(student, x:z)

louis-vines/tidyutils documentation built on May 21, 2019, 12:05 p.m.