Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

decimal.align

Turn numbers into strings with aligned decimal points


Description

Formats decimal numbers as strings with aligned decimal points.

Usage

decimal.align(x,dechar=".",nint=NA,ndec=NA,pad.left=TRUE)

Arguments

x

One or more decimal numbers.

dechar

The character used to separate the decimal part of a number.

nint

The number of characters to which the integer part of the numbers should be padded.

ndec

The number of characters to which the decimal part of the numbers should be padded.

pad.left

Whether the left (integer) side of the numbers should be padded as well as the right.

Details

decimal.align splits the incoming numbers at the decimal point and pads the decimal part and optionally the integer part so that when the numbers are displayed in a monospaced font the decimal points will be aligned. Note that if an integer or a decimal part without an integer is passed, the function will insert a zero for the missing part.

This is useful for displaying or storing aligned columns of decimal numbers when the user does not want to pad the decimal part with zeros as in the format function.

Value

The original numbers as strings, padded with spaces.

Author(s)

Jim Lemon

See Also

Examples

x<-c(1,2.3,44.55,666.777)
 decimal.align(x)

prettyR

Pretty Descriptive Stats

v2.2-3
GPL (>= 2)
Authors
Jim Lemon <drjimlemon@gmail.com>, Philippe Grosjean <phgrosjean@sciviews.org>
Initial release
2019-04-08

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.