Getting error “recursive indexing failed at level 2” in R when trying to recurse through list

佐手、 提交于 2019-12-13 16:01:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!