Skip to content
Prev 296090 / 398506 Next

How to aggregate combinations

Hello,

The problem can be solved using graph theory tools.

library(igraph)

edg <- read.table(text="
ID ID2
1    2
1    3
2    3
6    5
7    8
8    9
", header=TRUE)

(G <- graph(t(edg) - 1, directed=TRUE))  # igraph vertices are zero-based
V(G)$name <- 1:9

#V(G)$label <- V(G)$name
#plot(G, layout=layout.circle)

comp <- decompose.graph(G)
lapply(comp, function(x) colnames(get.adjacency(x)))

Hope this helps,

Rui Barradas

Em 30-05-2012 22:01, Oritteropus escreveu: