makeLevsPadNums: make a set of levels that consist of a prefix combined with...

makeLevsPadNumsR Documentation

make a set of levels that consist of a prefix combined with padded numeric values

Description

Makes a set of levels by combining a single string with strings formed by either left- or right-padding of numeric values so that the width of the padded string is at least ndigits. The prefix and the padded string are combined using the function paste0. If pad.char is "0", pad.direction is "right", and there is a mixture of integers and reals, full stops will be added to the integers as part of the padding process. Factor levels with a single-character prefix and a sequence of padded integers from 1 to the number of levels are often used as generic, abbreviated levels.

A warning is generated if there is more than one prefix string or non-numeric values are supplied to nums.

Usage

makeLevsPadNums(prefix, nums, ndigits = 2, pad.char = "0", pad.direction = "left")

Arguments

prefix

A string to use as the prefix to a set of padded numeric values.

nums

A vector of numeric values that are to be left- or right-padded using str_pad_left or str_pad_right from the package stringi. The width of the padded string will be at least ndigits.

ndigits

An integer specifying the minimum width of the padded string that is to be appended to the prefix.

pad.char

A string to use in padding the numeric values.

pad.direction

A string to specify whether to pad on the left or the right.

Value

A vector of the same length as nums, provided only a single prefix is provided.

Author(s)

Chris Brien

See Also

stringi::stri_pad_left, stringi::stri_pad_right.

Examples

treat.levs <- makeLevsPadNums("T", 1:12)

treat.levs <- makeLevsPadNums("T", seq(0.0, 2.5, 0.5), ndigits = 3, pad.dir = "r")

levs <- makeLevsPadNums("", 1:12)

dae documentation built on July 9, 2026, 5:08 p.m.