| network_wrangling | R Documentation |
cograph's verbs for reshaping a network. Every verb takes any supported
input (matrix, edge list, igraph, statnet network, tna model,
cograph_network), takes its options as named arguments, and returns a
cograph_network — or the input format when
keep_format = TRUE. There is no pipeline state to activate and
nothing to unpack afterwards: use as.data.frame() for the tidy edge
or node table.
Each verb returns a cograph_network, except
split_components(), which returns a list of them. With
keep_format = TRUE a matrix, igraph, statnet network or tna input
comes back in that format.
filter_nodes(), select_nodes()Keep nodes by expression, name, index, top-N, neighborhood or component.
filter_edges(), select_edges()Keep edges by expression, endpoints, bridges, mutuality or top-N.
select_neighbors(), select_component(),
select_top(), select_k_core()Named shorthands for the common selections.
split_components()One network per connected component.
threshold_edges()Keep edges by weight, count, proportion or density.
binarize()Replace weights with 0/1.
symmetrize()Combine opposite arcs into one edge.
normalize_weights()Rescale by row, column, maximum, total, or to [0, 1].
invert_weights()Turn similarities into distances.
to_undirected(), to_directed(),
reverse_edges()Change directedness.
remove_isolates()Drop nodes with no edges.
contract_nodes()Collapse groups of nodes into one.
spanning_tree(),
complement_network()Derived graphs.
reorder_nodes(), rename_nodes()Change node order or labels without changing the network.
simplify()Merge duplicate edges and drop loops.
add_nodes(), remove_nodes(),
add_edges(), remove_edges()Add and remove.
mutate_nodes(),
mutate_edges()Compute and store attributes.
bind_networks()Union, intersection or difference of two networks.
as_cograph(), to_matrix(),
to_igraph(), to_network(),
to_df(), and as.data.frame() on a
cograph_network (see as.data.frame.cograph_network).
Filtering edges does not remove nodes. This matches
igraph::delete_edges() and tidygraph. Nodes left without edges
raise a cograph_isolates_created warning; call
remove_isolates() to drop them, or pass
keep_isolates = FALSE.
Undirected results stay undirected. The weight matrix of an undirected result is symmetric, so nothing downstream re-detects it as directed.
Metadata survives. Node groups, estimation data, layout coordinates and the original source type are carried through every verb.
Malformed selections are errors. Unknown node names, out-of-
range or fractional indices, unknown measure names and a malformed
between raise a cograph_bad_selection error rather than
warning and returning something plausible.
ego_networks(), shortest_paths(),
disparity_filter(), detect_communities(),
summarize_clusters(), aggregate_layers().
adj <- matrix(c(0, .5, .8, 0,
.5, 0, .3, .6,
.8, .3, 0, .4,
0, .6, .4, 0), 4, 4, byrow = TRUE)
rownames(adj) <- colnames(adj) <- c("A", "B", "C", "D")
# One call, named arguments, a tidy table out
as.data.frame(threshold_edges(adj, minimum = 0.4))
# Verbs compose
adj |>
threshold_edges(minimum = 0.4) |>
remove_isolates() |>
mutate_nodes(deg = degree) |>
as.data.frame(what = "nodes")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.