Discussion:
[igraph] Question about exporting community detection results
Vivian Huang
2018-05-30 03:02:30 UTC
Permalink
Dear all

I used igraph in R to detect communities based on an unweighted
unidirectional edge list like the following:

ID1 ID2
1278 2876
3354 9973
.....................
5350 6672

The edge list was saved in a CSV file : "I:/network/ Edges 1997 to 1999.csv"

The code I wrote :

dat=read.csv(file.choose("I:/network/ Edges 1997 to 1999.csv"),header=TRUE)
el=as.matrix(dat)
el[,1]=as.character(el[,1])
el[,2]=as.character(el[,2])
g=graph.edgelist(el,directed=FALSE)
cluster_louvain(g,weights=NULL)

The code worked well. However, I couldn't figure out how to export the
community detection results to a CSV file. I would like to have a dataset
that looks like the following (the third column being the ID of a community
that a row belongs to):

ID1 ID2 CommunityID
1278 2876 A
3354 9973 C
.....................
5350 6672 A

Thank you for your help in advance!

Loading...