Skip to content

Instantly share code, notes, and snippets.

@tmastny
Created July 24, 2019 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmastny/89431d7b5facdeb6054df942475ff441 to your computer and use it in GitHub Desktop.
Save tmastny/89431d7b5facdeb6054df942475ff441 to your computer and use it in GitHub Desktop.
pivot_wider stuff
library(tidyr)
library(dplyr)
set.seed(324)
d <- tibble(
org = c(1, 1, 1, 2, 2, 3, 3, 3),
sport = c("fb", "sc", "bb", "fb", "bb", "fb", "sc", "bb"),
v1 = rnorm(8),
v2 = rnorm(8) * 2,
v3 = rnorm(8) * 10
)
d
d %>%
pivot_wider(
names_from = sport,
values_from = v1:v3,
values_fill = list(v1 = 0, v2 = 0, v3 = 0)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment