R igraph 手册页

如果您从 R 中使用 igraph,请使用此选项

igraph-vs-attributes {igraph}R 文档

查询或设置顶点序列中顶点的属性

描述

$ 运算符是一个语法糖,用于查询和设置顶点序列中顶点的属性。

用法

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

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

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

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

V(x) <- value

参数

x

一个顶点序列。对于 V<-,它是一个图。

i

索引。

value

顶点序列中顶点属性的新值。

name

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

详细信息

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

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

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

参见

其他顶点和边序列: E(), V(), igraph-es-attributes, igraph-es-indexing2, igraph-es-indexing, igraph-vs-indexing2, igraph-vs-indexing, print.igraph.es(), print.igraph.vs()

其他图属性: delete_edge_attr(), delete_graph_attr(), delete_vertex_attr(), edge_attr<-(), edge_attr_names(), edge_attr(), graph_attr<-(), graph_attr_names(), graph_attr(), igraph-dollar, set_edge_attr(), set_graph_attr(), set_vertex_attr(), vertex_attr<-(), vertex_attr_names(), vertex_attr()

示例

g <- make_(ring(10),
  with_vertex_(
    name = LETTERS[1:10],
    color = sample(1:2, 10, replace=TRUE)
  )
)
V(g)$name
V(g)$color
V(g)$frame.color <- V(g)$color

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

[包 igraph 版本 1.3.5 索引]