sequentialRange: Sequential Range

Description Usage Arguments Value Note Examples

View source: R/normalizingOperations.R

Description

Change a non-sequential vector of numeric identifiers into a vector of sequential identifiers.

Usage

1
sequentialRange(x, baseValue = 1)

Arguments

x

A numeric vector

baseValue

Determines the value the identifiers should start at

Value

A numeric vector

Note

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.

Examples

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)

wjhopper/whoppeR documentation built on May 4, 2019, 7:33 a.m.