4

I am trying to assign a vector as an attribute for a vertex, but without any luck:

# assignment of a numeric value (everything is ok)
g<-set.vertex.attribute(g, 'checked', 2, 3)
V(g)$checked

.

# assignment of a vector (is not working)
g<-set.vertex.attribute(g, 'checked', 2, c(3, 1))
V(g)$checked

checking the manual, http://igraph.sourceforge.net/doc/R/attributes.html it looks like this is not possible. Is there any workaround?

Up till now the only things I come up with are:

store this

  • information in another structure
  • convert vector to a string with delimiters and store as a string
4

1 回答 1

5

这工作正常:

## replace c(3,1) by list(c(3,1))
g <- set.vertex.attribute(g, 'checked', 2, list(c(3, 1)))
V(g)[2]$checked
[1] 3 1

编辑为什么这有效?当你使用:

    g<-set.vertex.attribute(g, 'checked', 2, c(3, 1))

你得到这个警告:

number of items to replace is not a multiple of replacement length

实际上,您尝试将长度 = 2 的 c(3,1) 放入长度= 1 的变量中。所以想法是用类似但长度= 1的东西替换c(3,1)。例如:

 length(list(c(3,1)))
[1] 1
> length(data.frame(c(3,1)))
[1] 1
于 2013-06-18T16:39:53.737 回答