igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

## Re: [igraph] threshold

 From: Gábor Csárdi Subject: Re: [igraph] threshold Date: Tue, 30 Mar 2010 09:58:31 +0200

```On Sun, Mar 28, 2010 at 4:30 PM, Tamas Nepusz <address@hidden> wrote:
> Hi,
>
>> Is there a direct way in iGraph to calculate a threshold that will retain
>> let's say 2% of the strongest weighted edges and convert a weighted graph to
>> a binary graph using this threshold ?
> No, since it is only a few lines of code using either the R or the Python
> interface. In Python, you can do something like this:
>
> weights = sorted(g.es["weight"], reverse=True)
> threshold = weights[len(weights) * 0.02]
> g.delete_edges(g.es.select(weight_lt = threshold))
> del g.es["weight"]
>
> --
> Tamas
[...]

The same in R:

weights <- sort(E(g)\$weight, decreasing=TRUE)
threshold <- weights[length(weights) * 0.02]
g2 <- delete.edges(g, which(E(g)\$weight < threshold)-1)
g2 <- remove.edge.attribute(g, "weight")

Gabor

--
Gabor Csardi <address@hidden>     UNIL DGM

```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]