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. ______________________________________________ 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.