Add one or more edge attributes to a graph

add_edge_attributes(object, attr_name, value, edgelist, overwrite = FALSE)

Arguments

object

graph

attr_name

vector with one or more names of attributes

value

vector, matrix, or data.frame

edgelist

matrix or dataframe containing the edgelist and edge attributes

overwrite

logical, should an edge attribute be overwritten if it already exists inside the graph?

Value

graph with the added edge attributes

Details

Consistent API to easily add one or more edge attributes to a graph of class igraph or network. Both the igraph and statnet packages do not have (simple) functions for this.

Adding edge attributes is easy, There are several options:

  • a vector with values specified in value and a name for the attribute specified in attr_name.

    This is only a very safe option if you know for sure that the order of the edges in value are identical to the order of the edges inside the graph object.!

  • a data.frame or matrix for value. Provide the names that the edge attributes should get in attr_name (which can be a vector with more than one name: the same number of names as there are columns in value). Note: any column names in value will be overridden by whatever is provided in attr_name.

    This is only a very safe option if you know for sure that the order of the edges in value are identical to the order of the edges inside the graph object!

  • an edgelist (data.frame or matrix) in edgelist. If attrname is not provided, then all attributes in edgelist are added to the graph. If attrname is provided, only the columns in edgelist are added to the graph that occur in attr_name.

    The edgelist is assumed to have at least three columns. The first column contains the sender and the second column contains the receiver of the edge (this is irrespective of the names of these columns and the sender-receiver order is irrelevant for undirected graphs). Any further columns are assumed to be edge attributes.

    This is the safe option, as the function makes sure that the edge attributes are added to the correct edge.