当我们使用 'betweenness' 函数 betweenness(g,weights=NULL,directed = FALSE) 时,如果图具有权重属性,即使我们写成 weights=NULL,该函数仍然会使用权重属性计算介数。但我想计算没有权重属性的介数。所以我觉得这个功能看起来很奇怪。为什么我们写 weights=NULL 的时候还是使用 weight 属性?
function (graph, v = V(graph), directed = TRUE, weights = NULL,
nobigint = TRUE, normalized = FALSE)
{
if (!is.igraph(graph)) {
stop("Not a graph object")
}
v <- as.igraph.vs(graph, v)
if (is.null(weights) && "weight" %in% list.edge.attributes(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
weights <- as.numeric(weights)
}
else {
weights <- NULL
}
on.exit(.Call("R_igraph_finalizer", PACKAGE = "igraph"))
res <- .Call("R_igraph_betweenness", graph, v - 1, as.logical(directed),
weights, as.logical(nobigint), PACKAGE = "igraph")
if (normalized) {
vc <- vcount(graph)
res <- 2 * res/(vc * vc - 3 * vc + 2)
}
if (getIgraphOpt("add.vertex.names") && is.named(graph)) {
names(res) <- V(graph)$name[v]
}
res
}