Given multiple vectors I'd like to return the unique combinations of columns across the vectors. Here is an example that works but isn't as fast as computationally fast as I'd like:
library(dplyr)
c_sort_collapse <- function(...){
c(...) %>%
sort() %>%
paste(collapse = ".")
}
unique_set <- function(...){
list(...) %>%
purrr::pmap_chr(c_sort_collapse) %>%
unique()
}
unique_set(c("a", "b", "a"), c("a", "a", "b"))
#> [1] "a.a" "a.b"
Is there a way to do this that is faster / better vectorized, i.e. doesn't depend on looping through each item (like happens in the purrr::pmap_chr() step)?