sparsematrix_from_edgelist: Convert edge list to sparse matrix

Description Usage Arguments Value Examples

View source: R/04_sparsematrix_from_edgelist.R

Description

Converts edge lists (class data.frame) to sparse matrices (class "dgCMatrix"). For unipartite edge lists that contain any nodes with outdegrees or indegrees equal to 0, it is recommended that users append self-ties to the edge list to ensure that the IDs of the rows and columns are ordered intuitively to the user.

Usage

1
2
3
4
5
6
7
8
sparsematrix_from_edgelist(
  data,
  sender_name = NULL,
  receiver_name = NULL,
  weight_name = NULL,
  duplicates = c("add", "remove"),
  is_bipartite = T
)

Arguments

data

Edge list to convert to sparse matrix. Must be in edge list format and of class data.frame, data.table, or tbl_df.

sender_name

Name of sender column. Defaults to the first column of an edge list.

receiver_name

Name of sender column. Defaults to the second column of an edge list.

weight_name

Name of edge weights. Defaults to edge weight = 1.

duplicates

How to treat duplicate edges from edge list. If option "add" is selected, duplicated edges and corresponding edge weights are collapsed via addition. Otherwise, duplicated edges or removed and only the first instance of a duplicated edge is used. Defaults to "add".

is_bipartite

Indicate whether input data is bipartite (rather than unipartite/one-mode). Defaults to TRUE.

Value

A sparse matrix of class dgCMatrix.

Examples

1
2
3
4
5
6
7
8
#make edge.list
   df <- data.frame(
     id1 = sample(x = 1:20, size = 100, replace = TRUE),
     id2 = sample(x = 1:10, size = 100, replace = TRUE),
     weight = sample(x = 1:10, size = 100, replace = TRUE)
   )
#convert to sparsematrix
   sparsematrix_from_edgelist(data = df)

BrianAronson/birankr documentation built on Nov. 13, 2021, 1:25 a.m.