我目前正在使用一个具有两个不同模式和两个不同属性集的二部网络。因此,第1行到第5行是一个模式,而角色A、B和C是一个不同的模式,他们形成了一些用1标记的连接。
a<-replicate( 3, numeric(5) )
b<-apply(a, c(1,2), function(x) sample(c(0,1),1))
rownames(b) <- rownames(c(1,2,3,4,5))
colnames(b) <-colnames(c("A","B","C"))
b
A B C
[1,] 1 0 1
[2,] 1 0 1
[3,] 0 0 0
[4,] 0 1 1
[5,] 1 1 0
c<-as.network(b, directed=T, bipartite =3)
e<-c('A',"B","C")
f<-c('tall','short','tall')
g<-data.frame(e,f)
colnames(g)<-c('person','height')
g
person height
A tall
B short
C tall如何将数据帧g中的高度属性仅分配给角色A、B和C?到目前为止,我已经根据A,B和C的顶点位置尝试了set.vertex.attribute
set.vertex.attribute(c, attrname= 'height', g$height, v = network.vertex.names(c)[6:9]) 但是我得到了以下错误
Vertex ID does not correspond to actual vertex in set.vertex.attribute.发布于 2020-01-08 03:59:14
我想我想通了。我自己在双向网络中也遇到了同样的问题,我从iGraph教程中借用了一些代码。
set.vertex.attribute(c,attrname = "height",
value = as.character(g$height),
v= match(c %v% "vertex.names",g$person))这对我来说很有效,不确定as.character对你是否有必要。您使用名称statnet通过"vertex.names“了解您想要的顶点。
https://stackoverflow.com/questions/59332310
复制相似问题