fillUpDecimals {survSpearman}R Documentation

Formats decimal part of numbers.

Description

The function adds zeros after the decimal point of each element of a numeric vector so that all elements have the same number of digits after the decimal point.

Usage

fillUpDecimals(numVec, howManyToFill, fill)

Arguments

numVec

A vector of numbers in a numeric or character format.

howManyToFill

The target number of digits after the decimal point. If howManyToFill is NULL (the default), then the function uses the maximum number of digits after the decimal point among the element of numVec.

fill

What character to insert as a filler to reach the target number of digits (characters) after the decimal point. The default is '0'.

Details

The function adds zeros (or other characters) after the decimal point of each element of numVec so that all elements have the same number of decimal places after the decimal point. Lower and upper case letters are treated as digits (see the examples). NA values are returned unchanged. It is not recommended to include elements with characters other than digits and letters into numVec because the function will not work as described for these elements.

Value

A character string with equal number of decimal places after the decimal point.

Author(s)

Svetlana K Eden, svetlanaeden@gmail.com

Examples

fillUpDecimals(c("2", "3.4", "A", NA))
fillUpDecimals(c("2", "3.4", "A.5", NA), howManyToFill = 3)
fillUpDecimals(c("2", "3.4", "A", NA), fill = "X")
fillUpDecimals(c("2", "3.4", "A", NA), howManyToFill = -3)
fillUpDecimals(c("2", "3.4", "A.zx", NA), fill = "?")
### It is not recommended to include elements
### with characters other than digits and letters
### because the function will not work as described
### for these elements
fillUpDecimals(c("2", "3.4", "A.zx", NA, "#", "#a"), fill = "?")


[Package survSpearman version 1.0.1 Index]