matrix_to_adjlist: Convert matrix into adjacency list

Description Usage Arguments Value Examples

View source: R/matrix_to_adjlist.R

Description

An NxN square matrix can be alternatively represented as an adjacency list containing NxN observations. This function performs that conversion.

Usage

1
matrix_to_adjlist(input_matrix, edge_col_name = "edge")

Arguments

input_matrix

A square NxN matrix, where N=number of nodes.

edge_col_name

The name of the column encoding the relation between two given nodes. This is probably 'edge' for adjacency matrices, or 'successor_value' for matrices encoding successor relations.

Value

A tibble with NxN observations, such that every row is a pairwise combination of two nodes ('from' and 'to'), and a column encoding the relationship between them.

Examples

1
2
3
4
5
6
`%>%` <- magrittr::`%>%`
successr::karate %>%
    tidygraph::as_tbl_graph(directed = F) %>%
    graph_to_adjlist() %>%
    adjlist_to_matrix() %>%
    matrix_to_adjlist()

psychNerdJae/successr documentation built on Dec. 22, 2021, 9:56 a.m.