igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] How to get the vertex itself not the index +write a graph i


From: Fatemeh a
Subject: Re: [igraph] How to get the vertex itself not the index +write a graph in a CSV format with all the attribute
Date: Sun, 16 Nov 2014 10:28:55 +0330



On Sat, Nov 15, 2014 at 6:36 PM, Gábor Csárdi <address@hidden> wrote:
On Sat, Nov 15, 2014 at 6:56 AM, Fatemeh a <address@hidden> wrote:
Hi,
I would like to get the neighborhood of each vertex and get the community membership of each of them and the size of the each community which each vertex belong to , please consider this example :

karate <- graph.famous("Zachary")
karate <-as.matrix(karate)

What is the point of this line?
 

yes,sorry ,this line (karate <-as.matrix(karate) ) has no point
 
wckarate <- walktrap.community(karate) 
neigh_com <-sapply(graph.neighborhood(karate,1,nodes=V(karate)),function(g,x) {
        membership(wckarate)[V(g)] })
neigh_size <-sapply(graph.neighborhood(karate,1,nodes=V(karate)), function(g) {
   sizes(wckarate)[membership(wckarate)[V(g)] })

This gives me:
Error: unexpected '}' in:
"neigh_size <-sapply(graph.neighborhood(karate,1,nodes=V(karate)), function(g) {
   sizes(wckarate)[membership(wckarate)[V(g)] }"
 
sorry for that , this is what I used :
neigh_size <-sapply(graph.neighborhood(karate,1,nodes=V(karate)), function(g) {
   sizes(wckarate)[membership(wckarate)[V(g)]] }) 

 

the problem is that it is working with the index rather than the each vertex id itself, and when I use graph.neighborhood it will index each vertex all over again so it is all wrong how to avoid this ?

Yes, this is very inconvenient, and will be fixed in the next major release. Until then, you can just index V(karate)$name with the numeric ids to get the symbolic ids.


thank you so much this is what I done and works fine :

library(igraph)
karate <- graph.famous("Zachary")
wckarate <- walktrap.community(karate)
V(karate)$name<-V(karate)
V(karate)$community<-membership(wckarate)
V(karate)$size<-sizes(wckarate)[membership(wckarate)]
graph_neighbours<-graph.neighborhood(karate,1,nodes=V(karate))
for(i in 1:vcount(karate)) {
 write.graph(graph_neighbours[[i]],file=c(as.character(V(karate)$name[i])),format="dot")
}

  I will really appreciate if you could help me with this as well :

after getting each graph neighbours I wish I could have a csv of file of all like this:

Node community

size

Node

Community

Neighbours community

size

Neighbours

community

Neighbours name

node

name

7

2

9

1

2

31

7

2

7

2

9

31

7

2

9

3

33

31

7

2

9

3

34

31


if I am not wrong the only format which keep all the attributes is "dot"
butis there any way to have a csv file like this ? and if not is there any way to write them in a single file as my own graph is really big ?

thank you so much for all your helps,
fatemeh

 

Gabor
 

thank you in advance,
fatemeh

--
regards
F..A

_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help



_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help




--
regards
F..A

reply via email to

[Prev in Thread] Current Thread [Next in Thread]