igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] How to get neighborhood info using igraph in R


From: Csardi Gabor
Subject: Re: [igraph] How to get neighborhood info using igraph in R
Date: Mon, 8 Sep 2008 15:52:28 +0200
User-agent: Mutt/1.5.9i

Amit, this will probably do it. You didn't tell whether 
you have tabulator or spaces in the file, hopefully 
the format is not sensitive to this.

g <- erdos.renyi.game(100, 2/100)
adj <- get.adjlist(g)
out <- file("/tmp/output.nei", open="w")
cat("Node\tNo of neighbors\tList of neighbors\n", file=out)
lapply(seq_along(adj), function(x) { 
   cat(x, "\t", length(adj[[x]]), "\t\t", sep="", file=out)
   cat(adj[[x]], sep="  ", file=out)
   cat("\n", file=out)
})
close(out)

Best,
Gabor

On Mon, Sep 08, 2008 at 02:28:19PM +0100, Amit Kumar wrote:
> Hello,
> I am using igraph in R to generate networks. I used erdos.renyi.game(100,
> 2/100) to generate a random graph.
> Now, I need neighbourhood info from this graph as output (*.nei or *.txt)
> which should look like as follows:-
> 
> Node          No of neighbours          List of neighbours
> 1                       2                              21   27
> 2                       5                              11   20  23  9  8
> -                        -                               --
> -                        -                               --
> -                        -                               --
> -                        -                               --
> 100                   4                              89  78  77  34
> 
> I am newbie. Please be kind and help.
> 
> regards
> Amit

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


-- 
Csardi Gabor <address@hidden>    MTA RMKI, ELTE TTK




reply via email to

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