Thank you. Very helpful. On Sat, Feb 16, 2013 at 2:25 PM, Tamás Nepusz <[email protected]> wrote: >> I have a data.frame with two columns, FROM and TO. Each are names of >> people where the person in FROM sent a message to the person in TO. >> There are many cases where person X sends to Y, but graph.data.frame >> doesn't appear to capture edge weight. > Are the weights defined explicitly in your data frame as a third column? If > so, igraph should add it to the generated graph: > >> df <- data.frame(from=c("a", "b", "a"), to=c("b", "a", "c"), weight=c(1,3,1)) >> g <- graph.data.frame(df) >> E(g)$weight > [1] 1 3 1 > > If the weights are not given in the data frame explicitly but you simply want > to use the number of email exchanges as weights, you can do this: > >> df <- data.frame(from=c("a", "b", "a"), to=c("b", "a", "b")) >> g <- graph.data.frame(df) >> E(g)$weight <- 1 >> g <- simplify(g, edge.attr.comb="sum") > > The call to graph.data.frame will simply create an unweighted graph where the > number of edges from X to Y will be equal to the number of messages sent by X > to Y. Then we simply assign a weight of 1 to each message and ask igraph to > collapse multiple edges into a single one while summing the edge attributes. > > -- > T. > > > _______________________________________________ > igraph-help mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/igraph-help
-- Jeff Hemsley Doctoral Candidate The Information School University of Washington http://staff.washington.edu/jhemsley/ http://somelab.net/author/jhemsley/ [email protected] _______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
