View source: R/createUniqueIds.R
createUniqueIds | R Documentation |
A function to create unique identifiers in a network presented in edgelist form.
createUniqueIds(data, from, to)
data |
Edgelist of a network, presented in |
from |
|
to |
|
This function creates two columns that can serve as unique identifiers. These IDs are in the range of 1:(number of nodes in the network). This is useful to create adjacency matrices when an unique identifier is composed of large numbers.
a list
containing the following components:
a data.frame
, giving for each node its original database identifier (column named database.id) and the new unique identifier (column named network.id) created; and
a data.frame
, which is the original dataset plus two new columns (columns "From" and "To") with the new unique identifiers of origin and destination
# Creating a data frame with movements from a source node (origin) # to a target node (destination) with identification codes between 1000 and 1050 origin <- sample.int(n = 50, size = 1000, replace = TRUE) + 1000 destination <- sample.int(n = 50, size = 1000, replace = TRUE) + 1000 database <- data.frame(origin = origin, destination = destination) # Creating new IDs starting from 1 new.database <- createUniqueIds(database, from = 'origin', to = 'destination') head(new.database$correspondence) head(new.database$movements)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.