0

After reading in a CSV of attributes, I'd like to apply these to an existing object (using a statnet-specific convention). If I knew the names ahead of time, I would do this:

pred_net %v% "id" <- nodeInfo$id
pred_net %v% "age" <- nodeInfo$age
pred_net %v% "sex" <- nodeInfo$sex
pred_net %v% "handed" <- nodeInfo$handed
pred_net %v% "lastDocVisit" <- nodeInfo$lastDocVisit

This works just fine, however, I don't know the names (id, age, sex, etc.) and would like to do something like this:

for (n in names(nodeInfo)) {
    pred_net %v% n <- nodeInfo$n
}

...which gives me an error:

Error in set.vertex.attribute(x, attrname = attrname, value = value) : 
  Inappropriate value given in set.vertex.attribute.

Presumably, this is because the variable names n are not handled as strings to pass to the %v% operator. Any ideas?

4

2 回答 2

2

您也可以选择一个变量[[characterVariable]](假设 nodeInfo 它是一个列表或一个data.frame):

for (n in names(nodeInfo)) {
    pred_net %v% n <- nodeInfo[[n]]
}
于 2013-10-24T17:00:02.147 回答
0

我知道这是很久以前的事了,但我遇到了同样的问题,所以遇到同样问题的人可能会发现我的解决方案很有用。我通过将因子转换为字符串来解决它。基本上在最初的 df 中,任何 var 都不应该是因素,因此请确保您使用 stringsAsFactors=F 然后网络将接受 df 属性。

于 2017-05-31T22:54:49.177 回答