Skip to content

Instantly share code, notes, and snippets.

@brshallo
Created May 31, 2020 18:22
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 brshallo/674ff06608c1a55fefb8d5dc49896d65 to your computer and use it in GitHub Desktop.
Save brshallo/674ff06608c1a55fefb8d5dc49896d65 to your computer and use it in GitHub Desktop.
# wrapper to put combn() output into a tibble (i.e. dataframe with nice printing options)
library(tidyverse)

combn_ttibble <- function(x, m = 2, fun = NULL, simplify = TRUE, ...){
  combn(x, m = m, FUN = fun, simplify = simplify, ...) %>% 
    t() %>% 
    tibble::as_tibble()
}

combn_ttibble(colnames(iris))
#> Warning: `as_tibble.matrix()` requires a matrix with column names or a `.name_repair` argument. Using compatibility `.name_repair`.
#> This warning is displayed once per session.
#> # A tibble: 10 x 2
#>    V1           V2          
#>    <chr>        <chr>       
#>  1 Sepal.Length Sepal.Width 
#>  2 Sepal.Length Petal.Length
#>  3 Sepal.Length Petal.Width 
#>  4 Sepal.Length Species     
#>  5 Sepal.Width  Petal.Length
#>  6 Sepal.Width  Petal.Width 
#>  7 Sepal.Width  Species     
#>  8 Petal.Length Petal.Width 
#>  9 Petal.Length Species     
#> 10 Petal.Width  Species

Created on 2020-05-31 by the reprex package (v0.3.0)

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