Get the constraint scores (based on Burt's Constraint Index) for one or more nodes in a graph.
get_constraint(graph, nodes = NULL)
graph | a graph object of class
|
---|---|
nodes | an optional vector of node IDs to consider for constraint scores. If not supplied, then constraint scores for all nodes in the graph will be calculated. |
a data frame with constraint scores for one or more graph nodes.
# Create a random graph using the # `add_gnm_graph()` function graph <- create_graph( directed = FALSE) %>% add_gnm_graph( n = 10, m = 15, set_seed = 23) # Get the constaint scores for all # nodes in the graph graph %>% get_constraint()#> id constraint #> 1 1 0.4686420 #> 2 2 0.4447222 #> 3 3 0.7506250 #> 4 4 0.4009333 #> 5 5 0.4367361 #> 6 6 0.3798222 #> 7 7 0.4686420 #> 8 8 0.8044444 #> 9 9 0.6277778 #> 10 10 0.0000000# Get the constaint scores # for nodes `5` and `7` graph %>% get_constraint( nodes = c(5, 7))#> id constraint #> 1 5 0.4367361 #> 2 7 0.4686420# Add the constraint scores # to the graph as a node # attribute graph <- graph %>% join_node_attrs( df = get_constraint(.)) # Display the graph's node data frame graph %>% get_node_df()#> id type label constraint #> 1 1 <NA> 1 0.4686420 #> 2 2 <NA> 2 0.4447222 #> 3 3 <NA> 3 0.7506250 #> 4 4 <NA> 4 0.4009333 #> 5 5 <NA> 5 0.4367361 #> 6 6 <NA> 6 0.3798222 #> 7 7 <NA> 7 0.4686420 #> 8 8 <NA> 8 0.8044444 #> 9 9 <NA> 9 0.6277778 #> 10 10 <NA> 10 0.0000000