ElegantPairingVec | R Documentation |
Unordered Pairing Function creating a new unique integer from two input integers in a data.frame
.
ElegantPairingVec (ID, data)
ID |
A character vector or integer vector containing the IDs of the data.frame. |
data |
a |
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.
A data.frame containing IDs and the computed integer.
Szudzik, M. (2006): An Elegant Pairing Function. Wolfram Science Conference NKS 2006.
ElegantPairingInt
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.