Question

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?

Was it helpful?

Solution

You can select a variable also with [[characterVariable]] (supposing nodeInfo it's a list or a data.frame) :

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

OTHER TIPS

I know this was a long time ago, but I had the same problem so people who run across the same problem might find my solution useful. I resolved it by casting factors to strings. Basically in the initial df none of the var should be factors so make sure you use stringsAsFactors=F and then network will accept df attribute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top