Description Usage Arguments Value Note Examples
View source: R/normalizingOperations.R
Change a non-sequential vector of numeric identifiers into a vector of sequential identifiers.
1 | sequentialRange(x, baseValue = 1)
|
x |
A numeric vector |
baseValue |
Determines the value the identifiers should start at |
A numeric vector
The minimum value in the input vector x will be the one which takes on the value baseValue, the second smallest value in x will take on the value baseValue + 1, etc.
Thus, if the input vector is not ascendingly sorted, the first values in the output will NOT be the lowest (i.e. will not be baseValue)
It is recommended that the output not be sorted, as there is no guarantee each unique id value will occur equally often in the input vector, and sorting may cause loss of information if this vector used to index another data structure or as observation identifies in a data frame. However, if you use the resulting vector verbatim to overwrite original ids in a data stucture, you can then sort the entire structure safely with no loss of information.
1 2 3 4 5 6 7 8 | ids <- c(rep(5,4),rep(c(6,8),each=6), rep(11,3), rep(3,5))
print(ids)
new_ids <- sequentialRange(ids)
print(new_ids)
testDataFrame <- data.frame(ids = testVec, scores = rnorm(length(testVec),5,3))
backup <- testDataFrame
testDataFrame$ids <- sequentialRange(testDataFrame$ids)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.