Recodes an edgelist such that ids go from 1 to n
recode(data, ...)
# S3 method for class 'data.frame'
recode(data, ...)
# S3 method for class 'matrix'
recode(data, ...)
A recoded edgelist as a two-column matrix/data.frame depending
on the class of data
. The output includes an attribute called "recode"
which contains a two column data.frame providing a mapping between the
previous code and the new code (see the examples)
Required for using most of the package's functions, as ids are used as a reference for accessing elements in adjacency matrices.
# Simple example ------------------------------------------------------------
edgelist <- cbind(c(1,1,3,6),c(4,3,200,1))
edgelist
#> [,1] [,2]
#> [1,] 1 4
#> [2,] 1 3
#> [3,] 3 200
#> [4,] 6 1
recoded_edgelist <- recode(edgelist)
recoded_edgelist
#> [,1] [,2]
#> [1,] 1 4
#> [2,] 1 3
#> [3,] 3 2
#> [4,] 5 1
#> attr(,"recode")
#> code label
#> 1 1 1
#> 5 2 200
#> 2 3 3
#> 4 4 4
#> 3 5 6
# Retrieving the "recode" attribute
attr(recoded_edgelist, "recode")
#> code label
#> 1 1 1
#> 5 2 200
#> 2 3 3
#> 4 4 4
#> 3 5 6