numericalAsCharacter: Convert numeric values to character that sort correctly

View source: R/internalFunctions.R

numericalAsCharacterR Documentation

Convert numeric values to character that sort correctly

Description

Small function that takes as input integer values (or values that can be converted to integer values) and converts them into character values that are 'padded' with zeros at the beginning of the numbers so that they will sort correctly.

Usage

numericalAsCharacter(values, prefix = "")

Arguments

values

vector of values to be converted into sortable character values

prefix

optional character string that will be added as prefix to the result

Details

The function determines the largest value and adds zeros to the front of smaller integers so that the resulting characters are the same number of digits. This allows standard sorting of the values to correctly sort.

The maximum number of zeros that will be added is 3. Input integers beyond that point will not be correctly fixed for sorting.

Negative integers will not be corrected, but left as-is

Value

A character vector

See Also

str_pad

Examples

numericalAsCharacter(c(-1, 5,10,20,100))

epurdom/clusterCells documentation built on Oct. 12, 2022, 4:44 a.m.