- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在分析 R 中的一个无向图。我试图(最终)编写一个函数来获得最大连通分量的大小(顶点数)与最大双连通分量的大小之比 - 任何随机图.我能够提取最大连通分量的大小,但在最大双连通分量的大小方面遇到问题。我开始在图 g 上使用 igraph 函数 biconnected_components:
bicomponent_list <- biconnected_components(g)
bicomponent_list$components # lists all of the components, including size and vertex names
length(bicomponent_list$components[[1]]) # returns number of vertices of first bicomponent
Then my half-baked idea was to somehow order this list in decreasing number of vertices, so that I can always call length(bicomponent_list$components[[1]]) and it will be the largest biconnected component. But I don't know how to sort this correctly. Perhaps I have to convert it to a vector? But I also don't know how to specify that I want the number of vertices in the vector. Does anyone know, or have a better way to do it? Thanks so much!
library(igraph)
# generating sample graph
g1 <- barabasi.game(100, 1, 5)
V(g1)$name <- as.character(1:100)
g2 <- erdos.renyi.game(50, graph.density(g1), directed = TRUE)
V(g2)$name <- as.character(101:200)
g3 <- graph.union(g1, g2, byname = TRUE)
# analyzing the bicomponents
bicomponent_list <- biconnected_components(g3)
bi_list <- as.list(bicomponent_list$components)
bi_list <- lapply(bi_list, length) # lists the sizes of all of the components that I want to reorder
My desired outcome would be ordering
bi_list
such thatlength(bicomponent_list$components[[1]])
returns the bicomponent with the most vertices.
最佳答案
components
属性是一个包含顶点列表的列表。您可以遍历它们并像这样找到它们的长度
sapply(bicomponent_list$components, length)
max()
中
max(sapply(bicomponent_list$components, length))
关于r - 在 R 中查找双连通分量的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33966826/
我是一名优秀的程序员,十分优秀!