问题
I am getting an error "recursive indexing failed at level 2" when I try to recurse through a list of graph vertices, matching their value with a set of colors in a list.
My list of colors is as follows:
colrs <- list(l = "blue, c = "red", n = "gray50")
Then I have a list of vertices in an igraph vs
object that have the values "l", "c", or "n" on a "value" attribute (i.e. V(g)$value).
The simple access that I'm trying to do is something like this:
colrs[[V(g)[1]$value]]
And the above works as I would like it to, returning the matching color. But when I try the following, I get the above mentioned error:
V(g)$color <- colrs[[V(g)$value]]
As you can see, what I'm trying to do is set a color
attribute on each vertex based on the value
attribute.
Can anyone tell me where I'm going wrong here? Would be greatly appreciated. I've not been able to find a good explanation anywhere else on the web.
来源:https://stackoverflow.com/questions/38979833/getting-error-recursive-indexing-failed-at-level-2-in-r-when-trying-to-recurse