Skip to content

Instantly share code, notes, and snippets.

@MCMaurer
Created October 18, 2022 17:59
Show Gist options
  • Save MCMaurer/0d303a1062c87c97eaa865f4097eba22 to your computer and use it in GitHub Desktop.
Save MCMaurer/0d303a1062c87c97eaa865f4097eba22 to your computer and use it in GitHub Desktop.
combining distinct values from a column where rows are otherwise duplicates
library(tidyverse)
tibble(group = c("A", "A", "B", "C"),
major = c("bio", "chem", "bio", "art")) %>%
group_by(group) %>%
summarise(major = str_c(major, collapse = "/")) %>%
separate(major, into = c("major1", "major2"), sep = "/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment