0

How am I able to access the column colored?

> str(C_Graph)
    Class 'igraph'  hidden list of 7
     $ : num 247
     $ : logi TRUE
     $ : num [1:476] 0 0 1 1 1 2 2 2 2 3 ...
     $ : num [1:476] 184 44 49 46 6 49 46 47 8 1 ...
     $ : num [1:245] 0 1 6 10 14 14 15 21 23 24 ...
     $ :List of 4
      ..$ : num [1:3] 1 0 1
      ..$ : Named list()
      ..$ :List of 1
      .. ..$ name: chr [1:247] "Peter" "Ranger" "Chris" "Thompson" ...
      ..$ :List of 1
      .. ..$ colored: num [1:476] 0 0 1 1 1 1 1 1 1 1 ...
     $ :<environment: 0x7fea2545be00> 
  • You can probably just do `C_Graph[[6]][[4]][[1]]`. The `hidden` thing is probably irrelevant - see https://stackoverflow.com/questions/9767959/what-does-hidden-list-in-the-output-of-str-mean – Andrew Gustar Jun 18 '23 at 09:34
  • @AndrewGustar It says subscript out of bounds. I don't think [[6]] leads me to where you think it does, e.g. [[1:4]] gives me Peter, Ranger, Chris, Thompson with some more additional variables about each of them – Egon Carter Jun 18 '23 at 09:38
  • 2
    Yes, you're right. From the `igraph` documentation, it might be `vertex_attr(C_Graph, "colored")`, or `V(C_Graph)$colored` – Andrew Gustar Jun 18 '23 at 09:47
  • in addition to Andrew's hint, the various methods to get/set graph/edge/vertex attributes might be helpful: https://igraph.org/r/doc/#G – I_O Jun 18 '23 at 10:00
  • @AndrewGustar both commands lead to NULL – Egon Carter Jun 18 '23 at 10:26
  • Try `vertex_attr_names(C_Graph)`, `edge_attr_names(C_Graph)`, and `graph_attr_names(C_Graph)` and see if any of them mentions `"colored"`. You can then use an `_attr(...)` statement as in previous comment. Looking at the lengths of the vectors, I guess `edge` is most likely in your case. – Andrew Gustar Jun 18 '23 at 10:55
  • Please read the information at the top of the [tag:r] tag page and provide a reproducible example. If this is an "igraph" class object and the igraph package is loaded using a library statement then V(g)$color gives the colors of the vertexes and E(g)$color for the edges where g is the graph. Using g defined at https://stackoverflow.com/questions/76486441/fitting-complex-non-linear-function-with-nls-in-r-gives-singular-gradient-erro?noredirect=1#comment134882622_76486441 that works. – G. Grothendieck Jun 18 '23 at 12:40

0 Answers0