n.code: Convert "Round" Integers to Short Strings and Back

View source: R/misc-goodies.R

n.codeR Documentation

Convert "Round" Integers to Short Strings and Back

Description

n.code convert “round integers” to short character strings. This is useful to build up variable names in simulations, e.g.

code2n is the inverse function of n.code().

Usage

n.code(n,    ndig = 1, dec.codes = c("", "d", "c", "k"))
code2n(ncod, ndig = 1, dec.codes = c("", "d", "c", "k"))

Arguments

n

integer vector.

ncod

character vector, typically resulting from n.code.

ndig

integer giving number of digits before the coding character.

dec.codes

character code for 1, 10, 100, 1000 (etc).

Value

n.code(n) returns a character vector of the same length as n.

code2n(ncod) returns a integer vector of the same length as ncod.

Usually, code2n(n.code(n)) == n.

Author(s)

Martin Maechler

Examples

n10 <-  c(10,20,90, 100,500, 2000,10000)
(c10 <- n.code(n10))#-> "1d" "2d" "9d" "1c" ..
stopifnot(code2n(c10) == n10)

sfsmisc documentation built on Aug. 10, 2023, 5:06 p.m.