Skip to content
Prev 244584 / 398502 Next

help requested

On Fri, Dec 10, 2010 at 07:20:55AM -0800, profaar wrote:
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.