[英]igraph making randomly generated node attribute values?
I have a code like the following: 我有如下代码:
library(igraph)
g <- make_empty_graph (100) %>%
set_vertex_attr("a", value = 0)
V(g)$a <- sample(c(0, 1), replace = TRUE, prob = c(0.1, 0.9))
V(g)$a
I want to randomize the node attribute value for "a" with a specific weight. 我想使用特定权重将“ a”的节点属性值随机化。 However if I run the program above, all the values for "a" turn to 1 with the occasional exception where the values alternate between 1 and 0. How do I fix this?
但是,如果我在上面运行该程序,则“ a”的所有值都会变为1,偶尔会有例外,其中值在1和0之间交替。如何解决此问题?
可能是您应该使用runif(100, 0, 1)
而不是sample(c(0, 1), replace = TRUE, prob = c(0.1, 0.9))
runif
sample(c(0, 1), replace = TRUE, prob = c(0.1, 0.9))
,从最小到最大的间隔, runif
样本均匀分布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.