find the distinct permutations of columns, particularly in graph applications were describing relationships between unordered nodes, or other applications were the order does not matter

similar_permutations(edges, to, from)

Arguments

edges

dataframe, tibble, The data structure to work on

to

tidy-eval, character The variable to group by

from

The column of values that will collapse into a list.

Value

The inputs pasted together as a character string.

Details

The inputs can be anything that casn be input into the paste function.

Note

ensure the total values to fold are sufficiently low tp preserve the pretty print aesthetic

experimant first if it helps

not well supported

on multiple data types

Examples

if(!require(dplyr)){library(dplyr)}
edges <- data.frame(
  to=sample(c('A','B','C','D'),size = 50,replace=TRUE),
  from=sample(c('A','B','C','D','E','F'),size = 50,replace=TRUE))

dplyr::count(edges,to,from)
#>    to from n
#> 1   A    A 2
#> 2   A    B 3
#> 3   A    C 1
#> 4   A    D 1
#> 5   A    E 1
#> 6   A    F 2
#> 7   B    A 3
#> 8   B    B 8
#> 9   B    C 2
#> 10  B    D 1
#> 11  B    E 2
#> 12  B    F 1
#> 13  C    A 2
#> 14  C    B 1
#> 15  C    C 1
#> 16  C    D 2
#> 17  C    E 1
#> 18  C    F 1
#> 19  D    A 3
#> 20  D    B 2
#> 21  D    C 4
#> 22  D    D 2
#> 23  D    E 2
#> 24  D    F 2

ordered = similar_permutations(edges,to,from)
 
dplyr::count(ordered, to ,from)
#> # A tibble: 19 × 3
#>    to    from      n
#>    <chr> <chr> <int>
#>  1 A     A         2
#>  2 A     B         3
#>  3 A     C         1
#>  4 A     D         1
#>  5 A     F         2
#>  6 B     A         3
#>  7 B     B         8
#>  8 B     C         2
#>  9 B     D         1
#> 10 B     E         2
#> 11 C     A         2
#> 12 C     B         1
#> 13 C     D         2
#> 14 D     A         3
#> 15 D     B         2
#> 16 D     C         4
#> 17 D     D         2
#> 18 D     E         2
#> 19 D     F         2