I have network data that looks like this:
data <- data.frame(id = as.character(1:20),
cluster = sample(c("a", "b", "c"), 20, replace = T))
head(data)
# id cluster
# 1 b
# 2 b
# 3 c
# 4 a
# 5 c
# 6 a
# 7 a
In the past, I've successfully gotten cluster data from links, but not the other way around. I tried using the igraph
package for network analysis but couldn't find a function that gave me a satisfactory result, and I didn't want to rely on a loop since they're inefficient and I in general try to stay away from them.
Expected Result
I'm wondering if there's an efficient way to create a new data.frame
with all possible "links" within a cluster, so that I end up with a data.frame
that looks like:
id1 id2 cluster
4 6 a
7 4 a
7 6 a
1 2 b
3 5 c