createUniqueIds: Create Unique Identifiers

View source: R/createUniqueIds.R

createUniqueIdsR Documentation

Create Unique Identifiers

Description

A function to create unique identifiers in a network presented in edgelist form.

Usage

createUniqueIds(data, from, to)

Arguments

data

Edgelist of a network, presented in data.frame format. Usually it is a data frame containing one row per animal movement, including information about origin and destination, number of animals, date of movement, etc.

from

character vector, indicate the column(s) used to characterize the source node (origin) of each edge

to

character vector, indicate the column(s) used to characterize the target node (destination) of each edge

Details

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.

Value

a list containing the following components:

correspondence

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

movements

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

Examples


# 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)


leb-fmvz-usp/epinemo documentation built on Nov. 27, 2022, 10:58 p.m.