[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Isolated Edges and Vertex Attributes
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] Isolated Edges and Vertex Attributes |
Date: |
Mon, 01 Aug 2011 12:27:51 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11 |
> I know how to delete nodes that have no edges at all but is there a way to
> delete isolated
> edges?
Find the connected components of your graph using clusters(), then delete
those vertices that participate in clusters of size 2. clusters() gives you
a result with three components:
cl <- clusters(g)
cl$membership -- is a vector where element i contains the cluster index of
vertex i-1 (unless you are using igraph 0.6 whose R interface uses 1-based
indexing, not 0-based)
cl$csize -- is a vector where element i gives you the size of cluster i
cl$no -- gives you the number of clusters
So, once you have cl, you can use which(cl$csize <= 2) to find the indices
of the clusters you will have to delete, then use cl$membership to find the
indices of the vertices you will have to delete:
small.clusters <- which(cl$csize <= 2)
vertices.to.delete <- which(cl$membership %in% small.clusters) - 1
g <- delete.vertices(g, vertices.to.delete)
> Secondly I have a data frame with 8 columns each representing a node
> attribute (except first column).
Then probably the easiest is to use graph.data.frame to construct your graph
directly from the data frame -- wouldn't that work in your case?
> g <- set.vertex.attribute(g, "x", index=V(g), value = n[,2])
Note that an easier way to achieve the same is V(g)$x <- n[,2]
> Also when I try to print the graph with the attributes using
>
> print(g, vertex.attributes=igraph.par("print.vertex.attributes"),
> names=TRUE, quote.names=TRUE)
>
> all I get is edges information and no attributes.
I'm not sure how this works in R (I use igraph from Python mostly), so there
could be an easier way to achieve the same thing, but the following line
definitely works:
sapply(list.vertex.attributes(g), function(x) { get.vertex.attribute(g, x) })
This gives you a table where each column corresponds to a vertex attribute
and columns are named according to the attributes. If you use this
frequently, you might want to save it as a function.
--
T.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [igraph] Isolated Edges and Vertex Attributes,
Tamas Nepusz <=