ElegantPairingVec {PPRL} | R 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 |
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
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)
[Package PPRL version 0.3.8 Index]