Pairs, given as rows of a matrix,
data.frame, or list, are processed to return
a list of paths, each identifying the connected pairs in the rows of x.
Arguments
- x
two-column
matrix,data.frame, or alistcontaining vectors of length two representing the pairs to be connected.- duplicate.rm
logicalindicating whether equal pairs (up to permutation) are to be omitted.
Value
A list each of whose elements give a path of connected pairs.
Each list element is a vector of length at least 2
(longer vectors > 2 in length identify the pairs connected in a path).
See also
zenplot() which provides the zenplot.
Other tools related to constructing zenpaths:
extract_pairs(),
graph_pairs(),
groupData(),
indexData(),
zenpath()
Examples
(pairs <- matrix(c(1,2,2,3,3,5,5,7,8,9), ncol = 2, byrow = TRUE))
#> [,1] [,2]
#> [1,] 1 2
#> [2,] 2 3
#> [3,] 3 5
#> [4,] 5 7
#> [5,] 8 9
connect_pairs(pairs)
#> [[1]]
#> [1] 1 2 3 5 7
#>
#> [[2]]
#> [1] 8 9
#>
nVars <- 5
pairs <- expand.grid(1:nVars, 1:nVars)
(pairs <- pairs[pairs[,1] < pairs[,2],])
#> Var1 Var2
#> 6 1 2
#> 11 1 3
#> 12 2 3
#> 16 1 4
#> 17 2 4
#> 18 3 4
#> 21 1 5
#> 22 2 5
#> 23 3 5
#> 24 4 5
connect_pairs(pairs)
#> [[1]]
#> [1] 2 1 3 2
#>
#> [[2]]
#> [1] 1 4 2
#>
#> [[3]]
#> [1] 3 4
#>
#> [[4]]
#> [1] 1 5 2
#>
#> [[5]]
#> [1] 3 5 4
#>
