Hello,

There is a function count.multiple that can be used to do what you want. You can also have a function return unique rows/edges. Here are three functions that count multiple edges.

library(igraph)
ee <- c(1,2,2,3,1,2,2,4,1,2,2,3)
g <- graph(ee)

plot(g)

# Returns a two column matrix with edge names and counts
edge.count1 <- function(g){
    result <- cbind(E(g), count.multiple(g))
    colnames(result) <- c("edge", "count")
    result
}

# Returns a three column matrix with edges and counts
edge.count2 <- function(g){
    cbind(get.edgelist(g), count.multiple(g))
}

# Adapted from R-Help:
#    G. Jay Kerns
#    Dec 22, 2007; 11:55pm
#    Re: number of count of each unique row
# Returns a data.frame of unique edges and counts
edge.count3 <- function(g){
    D <- data.frame(get.edgelist(g))  # convert to data frame
    ones <- rep(1, nrow(D))   # a column of 1s
    result <- aggregate(ones, by = as.list(D), FUN = sum)
    names(result) <- c("from", "to", "count")
    result
}

edge.count1(g)
edge.count2(g)
edge.count3(g)

Hope this helps,

Rui Barradas

Em 14-08-2012 22:09, Jonas Michaelis escreveu:
Dear all,


I have some network data - about 300 vertices and several thousand edges. I
am looking for a way to turn multiple edges into weights of the edges. I
looked around and - surprisingly? - haven't found anything. Is there an
easy way to do this?


Best, Jonas

        [[alternative HTML version deleted]]

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

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

Reply via email to