HI friends, I have very lengthy graph data in edge list format. I want to convert it into node list format. example: EDGE LIST FORMAT 1 2 1 3 1 4 1 5 2 3 2 4 3 2 4 1 4 3 4 5 5 2 5 4 ITS NODE LIST FORMAT SHOULD BE LIKE: 1 2 3 4 5 2 3 4 3 2 4 1 3 5 2 4 Kindly suggest me which package in R provides the support to do my task. Thank u friends in advance. -- View this message in context: http://r.789695.n4.nabble.com/help-requested-tp3082147p3082147.html Sent from the R help mailing list archive at Nabble.com.
awk '{arr[$1]=arr[$1] " " $2}END{for( i in arr){print i,arr[i]}}' edgelist.txt | sort -k1 On Fri, Dec 10, 2010 at 4:20 PM, profaar <profaar at live.com> wrote:> 1 2 > 1 3 > 1 4 > 1 5 > 2 3 > 2 4 > 3 2 > 4 1 > 4 3 > 4 ?5 > 5 2 > 5 4
Try this:> DFV1 V2 1 1 2 2 1 3 3 1 4 4 1 5 5 2 3 6 2 4 7 3 2 8 4 1 9 4 3 10 4 5 11 5 2 12 5 4> aggregate(V2 ~ V1, DF, paste, collapse = ' ')V1 V2 1 1 2 3 4 5 2 2 3 4 3 3 2 4 4 1 3 5 5 5 2 4 On Fri, Dec 10, 2010 at 1:20 PM, profaar <profaar@live.com> wrote:> > HI friends, > I have very lengthy graph data in edge list format. I want to convert it > into node list format. > > example: > EDGE LIST FORMAT > 1 2 > 1 3 > 1 4 > 1 5 > 2 3 > 2 4 > 3 2 > 4 1 > 4 3 > 4 5 > 5 2 > 5 4 > > ITS NODE LIST FORMAT SHOULD BE LIKE: > 1 2 3 4 5 > 2 3 4 > 3 2 > 4 1 3 > 5 2 4 > > Kindly suggest me which package in R provides the support to do my task. > Thank u friends in advance. > -- > View this message in context: > http://r.789695.n4.nabble.com/help-requested-tp3082147p3082147.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
On Fri, Dec 10, 2010 at 07:20:55AM -0800, profaar wrote:> > HI friends, > I have very lengthy graph data in edge list format. I want to convert it > into node list format. > > example: > EDGE LIST FORMAT > 1 2 > 1 3 > 1 4 > 1 5 > 2 3 > 2 4 > 3 2 > 4 1 > 4 3 > 4 5 > 5 2 > 5 4 > > ITS NODE LIST FORMAT SHOULD BE LIKE: > 1 2 3 4 5 > 2 3 4 > 3 2 > 4 1 3 > 5 2 4 > > Kindly suggest me which package in R provides the support to do my task.How long the list of egdes is? For not too large lists, consider also library(graph) G <- new("graphNEL", edgemode="directed") G <- addNode(as.character(1:5), G) edges <- read.table(file=stdin(), colClasses="character") 1 2 1 3 1 4 1 5 2 3 2 4 3 2 4 1 4 3 4 5 5 2 5 4 G <- addEdge(from=edges[, 1], to=edges[, 2], G) edgeL(G) $`1` $`1`$edges [1] 2 3 4 5 $`2` $`2`$edges [1] 3 4 $`3` $`3`$edges [1] 2 $`4` $`4`$edges [1] 1 3 5 $`5` $`5`$edges [1] 2 4 Very large lists can be handled by unix/linux sort command (if not sorted already) and by extracting the end-nodes of the edges starting in each node. In a sorted file, they form blocks of consecutive lines, so a simple text processing with perl is sufficient. Petr Savicky.