Ask Your Question
1

How can I export the constraints of igraph to a data.frame but without including the node identifiers?

asked 2023-05-03 15:22:26 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-03 15:47:02 +0000

lalupa gravatar image

You can use the as_data_frame() function from igraph and then remove the first column which contains the node identifiers. Here is an example:

library(igraph)

# create a sample graph with constraints
g <- graph.formula(1-2-3-4-5, 2-4-5)
set.vertex.attribute(g, "c1", c(1, 0, 0, 0, 1))
set.vertex.attribute(g, "c2", c(1, 0, 0, 1, 1))

# export constraints to data frame without node identifiers
df <- as_data_frame(g, what = "vertices", attrs = c("c1", "c2"))
df <- df[, -1]

The resulting data frame df will have the constraints in columns, without the node identifiers.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-03 15:22:26 +0000

Seen: 12 times

Last updated: May 03 '23