跳到内容

$ 操作符是一种语法糖,用于查询和设置边序列中边的属性。

用法

# S3 method for class 'igraph.es'
x[[i]] <- value

# S3 method for class 'igraph.es'
x[i] <- value

# S3 method for class 'igraph.es'
x$name

# S3 method for class 'igraph.es'
x$name <- value

E(x, path = NULL, P = NULL, directed = NULL) <- value

参数

x

一个边序列。对于 E<-,它是一个图。

i

索引。

value

边序列中边属性的新值。

name

要查询或设置的边属性的名称。

path

选择沿路径的边,路径由顶点序列给出。参见 E()

P

通过顶点对选择边。参见 E()

directed

是否对 pathP 参数使用边的方向。

一个向量或列表,包含序列中边的属性 name 的值。对于数值型、字符型或逻辑型属性,它是一个适当类型的向量,否则它是一个列表。

详细信息

$ 的查询形式是 edge_attr() 的快捷方式,例如 E(g)[idx]$attr 等同于 edge_attr(g, attr, E(g)[idx])

$ 的赋值形式是 set_edge_attr() 的快捷方式,例如 E(g)[idx]$attr <- value 等同于 g <- set_edge_attr(g, attr, E(g)[idx], value)

示例

# color edges of the largest component
largest_comp <- function(graph) {
  cl <- components(graph)
  V(graph)[which.max(cl$csize) == cl$membership]
}
g <- sample_(
  gnp(100, 1 / 100),
  with_vertex_(size = 3, label = ""),
  with_graph_(layout = layout_with_fr)
)
giant_v <- largest_comp(g)
E(g)$color <- "orange"
E(g)[giant_v %--% giant_v]$color <- "blue"
plot(g)