zenplots (version 1.0.6)

connect_pairs: Connecting Possibly Overlapping Pairs Into a List of Paths

Description

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.

Usage

connect_pairs(x, duplicate.rm = FALSE)

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).

Arguments

x

two-column matrix, data.frame, or a list containing vectors of length two representing the pairs to be connected.

duplicate.rm

logical indicating whether equal pairs (up to permutation) are to be omitted.

Author

Marius Hofert and Wayne Oldford

See Also

zenplot() which provides the zenplot.

Other tools related to constructing zenpaths: extract_pairs(), graph_pairs(), groupData(), indexData(), zenpath()

Examples

Run this code
## First something simple.
(pairs <- matrix(c(1,2,2,3,3,5,5,7,8,9), ncol = 2, byrow = TRUE))
## Connect pairs into separate paths defined by the row order.
connect_pairs(pairs)

## Now something different
nVars <- 5
pairs <- expand.grid(1:nVars, 1:nVars)
## and take those where
(pairs <- pairs[pairs[,1] < pairs[,2],])
connect_pairs(pairs)

## Something more complicated.
## Get weights
set.seed(27135)
x <- runif(choose(nVars,2)) # weights

## We imagine pairs identify edges of a graph with these weights
## Get a zenpath ordering the edges based on weights
(zp <- zenpath(x, pairs = pairs, method = "strictly.weighted"))

## And connect these giving the list of paths
connect_pairs(zp)

Run the code above in your browser using DataLab