'Converting Vertex Attributes with igraph in R
I have been trying to convert to integer a vertex attribute I've created with the following command:
vertex_attr(net_frequency, "x") <- as.integer(10:14:13:10:19:9:13:14:21:11:17:14:11:9:11:7:17:9:9:8:13:15:19:9:1:8:12:3:9:16:10:5:5:4:10:3:10:14:3:3:10:4:3:6:10:14:6:12:16:13:10:3:13:6:15:9:7:4:1:6:3:3:1:12:11:15)
Though, when I try to check to be sure it was done properly, I get the following:
typeof(get.vertex.attribute(net_frequency,"x"))
[1] "character
Am I checking this wrongly? Converting wrongly?
Thank you very much for your attention.
Solution 1:[1]
Currently it is not possible to convert the type of an attribute with igraph.
> g<-make_graph(c(1,2))
> V(g)$foo <- c('a', 'b')
> V(g)$foo <- c(1, 2)
> V(g)$foo
[1] "1" "2"
You will need to delete the attribute and re-create it with a different type. For example, to convert the above c('1', '2') to a numeric c(1, 2), you could use the following:
g <- g %>% delete_vertex_attr('foo') %>% set_vertex_attr('foo', value=as.numeric(V(g)$foo))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Szabolcs |
