ElegantPairingVec: Simple Pairing Function

View source: R/RcppExports.R

ElegantPairingVecR Documentation

Simple Pairing Function

Description

Unordered Pairing Function creating a new unique integer from two input integers in a data.frame.

Usage

ElegantPairingVec (ID, data)

Arguments

ID

A character vector or integer vector containing the IDs of the data.frame.

data

a data.frame consisting of two columns containing the integers on which the pairing function is to be applied.

Details

With two of non-negative integers x and y as an input, the pairing is computed as:

elegantPairing(x, y) = (x * y) + floor ((|x - y| - 1)^2) / 4)

The function is commutative. x and y have to be non-negative integers. The function outputs a single non-negative integer that is uniquely associated with that unordered pair.

Value

A data.frame containing IDs and the computed integer.

Source

Szudzik, M. (2006): An Elegant Pairing Function. Wolfram Science Conference NKS 2006.

See Also

ElegantPairingInt

Examples

# Load test data
testFile <- file.path(path.package("PPRL"), "extdata/testdata.csv")
testData <- read.csv(testFile, head = FALSE, sep = "\t",
  colClasses = "character")

# Create numeric data frame of day and month of birth
dataInt <- data.frame(as.integer(testData$V4), as.integer(testData$V5))

# Use unordered pairing on day and month
res <- ElegantPairingVec(testData$V1, dataInt)


PPRL documentation built on Nov. 10, 2022, 5:41 p.m.

Related to ElegantPairingVec in PPRL...