insert_zeros: insert zeros into a character vector

Description Usage Arguments Details Value Methods (by class)

View source: R/fun-insert_zeros.R

Description

Insert a string of zeros into every item of a character vector. A1 becomes A01. The orginal intent was to fix sorting of strings where 2 > 12 but 02 < 12. More robust options were built in just in case.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
insert_zeros(x, ...)

## S3 method for class 'character'
insert_zeros(x, zeros = "auto", after = 1, ...)

## S3 method for class 'factor'
insert_zeros(x, zeros = "auto", after = 1, ...)

## S3 method for class 'integer'
insert_zeros(x, zeros = "auto", after = 1, ...)

## S3 method for class 'double'
insert_zeros(x, zeros = "auto", after = 1, ...)

## Default S3 method:
insert_zeros(x, zeros = "auto", after = 1, ...)

Arguments

x

character or integer vector; double vectors are handled only if they can be converted to integer and pass as all.equal

...

arguments passed to methods

zeros

number of 0 characters to insert; see Details

after

position of the character after which the zeros will be inserted

Details

The zeros argument can be a fixed number but it defaults to auto. Then: if X is of length 1, adds 1 0; if X is longer than 1, adds to each element a number of 0 so that all elements of X have an equal number of characters.

Value

Modified character vector, where strings of zeros have been inserted at the specified position.

Methods (by class)


olobiolo/siscreenr documentation built on Nov. 26, 2021, 3:08 p.m.