add_edges: Add edges to graph

View source: R/add_edges.R

add_edgesR Documentation

Add edges to graph

Description

Add edges to graph

Usage

add_edges(
  graph_id,
  edges,
  edge_src_col = 1,
  edge_dst_col = 2,
  edge_weight_col,
  edge_type_col,
  auto_add_vertices = TRUE
)

Arguments

graph_id

the graph to which to add the edges and vertices. Should be of type chickenwire.

edges

a data.frame withe edges. Should contain at least two columns: source vertex id's of the edge and destination id's. By default it is assumed that these are in the first two columns of the data.frame (see edge_src_col and edge_dst_col).

edge_src_col

name or number of the column from edges containing the source vertex id's of the edges. Column should contain integer values.

edge_dst_col

name or number of the column from edges containing the destination vertex id's of the edges. Column should contain integer values.

edge_weight_col

name or number of the column from edges containing the weights of the edges. When omitted weights of 1 are assumed. Column should contain numeric values.

edge_type_col

name or number of the column from edges containing the types of the edges. When omitted all edges have type 1. Should be of type integer.

auto_add_vertices

automatically create vertices when an edge contains id's that do not exist yet. When vertices is given this parameter is set to FALSE.

Details

Note that the original graph_id is modified.

Value

Modifies graph_id and returns graph_id.

Examples

# Create graph with three vertices and 5 edges between them.
g <- create_graph()
g <- add_edges(g, data.frame(src = c(1,1,2,2,3), dst = c(2,3,1,3,1)))
print(g)
delete_graph(g)

# Create graph with four vertices and 5 edges between them; one of the
# vertices does not have edges.
g <- create_graph()
g <- add_vertices(g, 1:4)
g <- add_edges(g, data.frame(src = c(1,1,2,2,3), dst = c(2,3,1,3,1)))
print(g)
delete_graph(g)


djvanderlaan/chickenwire-r documentation built on July 19, 2022, 1:16 a.m.