igraph-help
[Top][All Lists]

## [igraph] per-vertex statistics of edge weights

 From: Sam Steingold Subject: [igraph] per-vertex statistics of edge weights Date: Wed, 15 Aug 2012 14:04:18 -0400 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

I have a graph with edge and vertex weights, stored in two data frames:

--8<---------------cut here---------------start------------->8---
vertices <- data.frame(vertex=c("a","b","c","d"),weight=c(1,2,1,3))
edges <- data.frame(src=c("a","a","b","c","d"),dst=c("b","c","d","d","a"),
weight=c(1,2,1,3,1))
--8<---------------cut here---------------end--------------->8---

I can create a graph from this data:

--8<---------------cut here---------------start------------->8---
library(igraph)
graph <- graph.data.frame(edges, vertices = vertices, directed=FALSE)
--8<---------------cut here---------------end--------------->8---

what I want is to compute some edge weight stats (mean/median/max/min/)
for each vertex.

I guess I can do something like

--8<---------------cut here---------------start------------->8---
> sapply(vertices\$vertex, function (v) mean(E(g)[inc(v)]\$weight))
Note: no visible global function definition for 'inc'
[1] 1.333333 1.000000 2.500000 1.666667
--8<---------------cut here---------------end--------------->8---

but I was wondering if this is TRT, given the correct answer with a
scary note.

Thanks!

--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://palestinefacts.org http://mideasttruth.com
http://thereligionofpeace.com http://openvotingconsortium.org
If you have no enemies, you are probably dead.