Skip to contents

augment_nodelist() augments the supplied node list by adding graph-based measures as node attributes.

Usage

augment_nodelist(nodelist, edgelist = NULL, graph = NULL)

Arguments

nodelist

a "netlit_nodelist" object, the output of a call to make_nodelist.

edgelist

optional; an "netlit_edgelist" object, the output of a call to make_edgelist.

graph

an igraph object; the output of a call to igraph::graph_from_data_frame(edgelist).

Details

When edgelist or graph are supplied, the "degree" node attribute is added, resulting from igraph::degree(graph, mode = "in"). (If graph is not supplied but edgelist is, igraph::graph_from_data_frame() will be run on edgelist first.) In any case, the "betweenness" attribute is added, resulting from igraph::betweenness.

Value

The argument supplied to ndoelist with one or two columns added. When edgelist or graph are supplied, the "degree" column is added. In any case, the "betweenness" column is added.

Examples

data("literature")
data("node_attributes")

nodelist <- make_nodelist(literature,
                          node_attributes = node_attributes)

edgelist <- make_edgelist(literature,
                          edge_attributes = c("cites", "cites_empirical"))

nodelist_augmented <- augment_nodelist(nodelist,
                                       edgelist = edgelist)

str(nodelist_augmented)
#> Classes ‘netlit_nodelist’ and 'data.frame':	56 obs. of  6 variables:
#>  $ node        : chr  "computers" "number of competitive districts" "partisan advantage" "partisan gerrymandering" ...
#>  $ type        : chr  "condition" "goal" "goal" "condition" ...
#>  $ degree_in   : num  0 1 6 1 2 0 0 0 0 2 ...
#>  $ degree_out  : num  2 2 8 7 6 2 3 6 6 1 ...
#>  $ degree_total: num  2 3 14 8 8 2 3 6 6 3 ...
#>  $ betweenness : num  0 64 112 42 79 ...
#>  - attr(*, "node")= chr "node"

if (FALSE) {
#Same results:
graph <- igraph::graph_frm_data_from(edgelist)
nodelist_augmented <- augment_nodelist(nodelist,
                                       graph = graph)
}