Skip to content
Prev 359634 / 398502 Next

How to form groups for this specific problem?

Satish,

If you rearrange your data into a network of nodes and edges, you can use
the igraph package to identify disconnected (mutually exclusive) groups.

# example data
df <- data.frame(
  Component = c("C1", "C2", "C1", "C3", "C4", "C5"),
  TLA = c("TLA1", "TLA1", "TLA2", "TLA2", "TLA3", "TLA3")
)

# characterize data as a network of nodes and edges
nodes <- levels(unlist(df))
edges <- apply(df, 2, match, nodes)

# use the igraph package to identify disconnected groups
library(igraph)
g <- graph(edges)
ngroup <- clusters(g)$membership
df$Group <- ngroup[match(df$Component, nodes)]
df

  Component  TLA Group
1        C1 TLA1     1
2        C2 TLA1     1
3        C1 TLA2     1
4        C3 TLA2     1
5        C4 TLA3     2
6        C5 TLA3     2

Jean

On Sun, Mar 27, 2016 at 7:56 PM, Satish Vadlamani <
satish.vadlamani at gmail.com> wrote: