Skip to content

Instantly share code, notes, and snippets.

@jmcastagnetto
Created March 24, 2022 17:53
Show Gist options
  • Save jmcastagnetto/16e5b2383e5e998a754cd966c1f9cb77 to your computer and use it in GitHub Desktop.
Save jmcastagnetto/16e5b2383e5e998a754cd966c1f9cb77 to your computer and use it in GitHub Desktop.
pivot_wider() on a char column
library(tidyverse)
d <- tibble(
id = c(1, 1, 2, 2),
foo = c("oh", "no", "oh", "no"),
bar = c("hmmm", "ok", "right", "sure?")
)
d %>%
pivot_wider(
names_from = foo,
values_from = bar
)
@jmcastagnetto
Copy link
Author

Output

# A tibble: 2 × 3
     id oh    no   
  <dbl> <chr> <chr>
1     1 hmmm  ok   
2     2 right sure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment