How do I create a self loop in igraph R?
How do I add self loop
to the graph next to the change Adjacency matrix
that changes c(i,i)=1
, is there a function that does this in the package igraph
R
?
Edit : creating a graph:
network=read.csv(file.choose())
network[,1]=as.character(network[,1])
network[,2]=as.character(network[,2])
mygraph=graph.data.frame(network,directed=TRUE)
E(mygraph)$weight=as.numeric(network[,3])
reproducible example:
karate <- graph.famous("Zachary")
E(karate)$weight <- 2
adjacency<-get.adjacency(karate,
attr="weight", edges=FALSE, names=TRUE)
for (i in 1:vcount(karate)){
adjacency[i,i]<-1
}
karate2<-graph.adjacency(adjacency, mode="directed", weighted=TRUE)
I am looking for a faster and easier solution, maybe this is a function.
+3
source to share