Make edgelist
make_edgelist.Rd
make_edgelist
makes an edge list from the supplied data frame. An edge list is a data frame with a "from" column, a "to" column, and, optionally, columns containing edge attributes, where each row is a directed edge.
Arguments
- data
a data set with a "from" column and a "to" column, where each row represents a directed edge. (See the
from
andto
arguments below if these columns have names other than"from"
and"to"
.)- edge_attributes
an optional character vector of the names of columns in
data
containing edge attributes.- from
the name of the column in
data
that should be considered the "from" column, i.e., representing the nodes from which directed edges emanate. Default is"from"
.- to
the name of the column in
data
that should be considered the "to" column, i.e., representing the nodes to which directed edges point. Default is"to"
.
Value
A netlit_edglist
object, which is a data frame identical to data
except for the following:
all missing values will have been removed (with a warning if present in
data
)only the
from
,to
, andedge_attributes
columns will be retained, with thefrom
andto
columns as the first two columnsan added column
"edge_betweenness"
will be present containing the edge betweenness for each edgethe attribute
"edge_attributes"
will contain the values supplied toedge_attributes
, if any
Details
make_edgelist()
creates a pared down version of data
containing only the from
, to
, and edge_attributes
columns, and an added "edge_betweenness"
column containing edge betweennesses as produced by igraph::edge_betweenness()
.
Examples
data("literature")
edgelist <- make_edgelist(literature,
edge_attributes = c("cites", "cites_empirical"))
str(edgelist)
#> Classes ‘netlit_edgelist’ and 'data.frame': 69 obs. of 5 variables:
#> $ from : chr "computers" "computers" "number of competitive districts" "partisan advantage" ...
#> $ to : chr "detect gerrymandering" "public participation" "preserve communities of interest" "proportionality" ...
#> $ cites : chr "Altman & McDonald 2010; Wang 2016; Altman & McDonald 2011; Ramachandran & Gold 2018" "Altman & McDonald 2010; Altman & McDonald 2011" "Gimpel & Harbridge-Yong 2020" "Caughey et al. 2017; Tamas 2019" ...
#> $ cites_empirical : chr "Wang 2016" NA "Gimpel & Harbridge-Yong 2020" NA ...
#> $ edge_betweenness: num 2 1 86 19.5 13.5 7 2 1 1 8 ...
#> - attr(*, "from")= chr "from"
#> - attr(*, "to")= chr "to"