按顶点名称排列的边序列

发布于 2024-09-19 10:32:00 字数 543 浏览 6 评论 0原文

好吧,我正在使用 igraph 包,在一个小例子中,我想通过分配给顶点的名称来选择边。

library(igraph)

g <- barabasi.game(8)

labels<-c("G1","G2","G3","T1","T2","T3","H1","H2")

V(g)$name<-labels

现在我的边列表已经这种形式

> E(g)
Edge sequence:

    [0] G2 -> G1
    [1] G3 -> G2
    [2] T1 -> G2
    [3] T2 -> G3
    [4] T3 -> G1
    [5] H1 -> G1
    [6] H2 -> H1

我现在想要的是找到一种方法,而不是使用它

E(g)[1%--%2]

做更像 E(g)[G2%--%G1] (通过我指定的名称调用顶点)或等效的方式通过所涉及顶点的名称了解一些边属性。

Well, I'm working with the igraph package, and I'd like to pick the edges by the name that I've assigned to their vertex, in a tiny example..

library(igraph)

g <- barabasi.game(8)

labels<-c("G1","G2","G3","T1","T2","T3","H1","H2")

V(g)$name<-labels

Now My edge list hast this form

> E(g)
Edge sequence:

    [0] G2 -> G1
    [1] G3 -> G2
    [2] T1 -> G2
    [3] T2 -> G3
    [4] T3 -> G1
    [5] H1 -> G1
    [6] H2 -> H1

What i want now is to find a way of, instead of using this

E(g)[1%--%2]

doing something more like E(g)[G2%--%G1] (calling the vertex by the name i've assigned), or an equivalent way of knowing some edges attributes by the name of the vertex involved.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情话墙 2024-09-26 10:33:08

将顶点名称括在引号中。这提供了与使用顶点编号相同的输出。这适用于 igraph 0.7.1。

例如:

> E(g)[1%--%8]
Edge sequence:
    e         
e [7] H2 -> G1

> E(g)['H2'%--%'G1']
Edge sequence:
    e         
e [7] H2 -> G1

Enclose the vertex names in quotes. This gives identical output to using the vertex number. This works in igraph 0.7.1.

For example:

> E(g)[1%--%8]
Edge sequence:
    e         
e [7] H2 -> G1

> E(g)['H2'%--%'G1']
Edge sequence:
    e         
e [7] H2 -> G1
风苍溪 2024-09-26 10:32:57

这对于 igraph 的 0.5 分支来说是不可能的,但开发版本 (0.6) 添加了对基于顶点的 name 属性而不是数字 ID 引用顶点的支持。我不知道如何做到这一点,因为我不熟悉 R 界面。尝试订阅 igraph-help 邮件列表 并在那里询问,因为这绝对是已经发生过的事情最近在 igraph 0.6 中解决了。

This is not possible with the 0.5 branch of igraph, but the development version (0.6) adds support for referring to vertices based on their name attribute instead of their numeric IDs. I'm not sure how to do that as I am not familiar with the R interface. Try to subscribe to the igraph-help mailing list and ask there as this is definitely something that has been solved recently in igraph 0.6.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文