I think this works correctly, but I am looking to mimic something similar to a Facebook Friend suggestion. Simply, Iβm looking to find connections of the 2nd degree (friends of your friends with whom you have no connection). I want to save this as a directed graph and identify external connections of the second degree (to which your friends connect).
I believe that my dummy code achieves this, but since the link is to indexes, not vertex labels, I was hoping you could help me change the code to return useful names.
### create some fake data library(igraph) from <- sample(LETTERS, 50, replace=T) to <- sample(LETTERS, 50, replace=T) rel <- data.frame(from, to) head(rel) ### lets plot the data g <- graph.data.frame(rel) summary(g) plot(g, vertex.label=LETTERS, edge.arrow.size=.1) ## find the 2nd degree connections d1 <- unlist(neighborhood(g, 1, nodes="F", mode="out")) d2 <- unlist(neighborhood(g, 2, nodes="F", mode="out")) d1;d2; setdiff(d2,d1)
Returns
> setdiff(d2,d1) [1] 13
Any help you can provide would be great. Obviously, I want to stay in R.
source share