strip0: Strip "0" from beginning of numbers printed by R.

View source: R/strip0.R

strip0R Documentation

Strip "0" from beginning of numbers printed by R.

Description

Takes an object x of class "character" or "numeric". Returns an object of class "character" in which the leading zero has been removed. By default, it also rounds the number-string that it returns to two decimal places. Example: both 0.3445 and "0.3445" are transformed to ".34".

Usage

strip0(x, dp = 2)

Arguments

x

Object of class "character" or "numeric."

dp

Integer specifying the number of decimal places in the returned string. Can be NULL, in which case no rounding is performed.

Details

If x has no leading zero, the returned object is still rounded to dp decimal places.

Examples

strip0("0.346")  #  ".35"
strip0(0.346)    #  ".35"
strip0(.346)     #  ".35"
strip0(5.346)    # "5.35"

strip0(c("0.789", ".2346", 53.3, 53.346))  # c(".79", ".23", "53.3", "53.35")


jbullock35/Bullock documentation built on April 1, 2022, 6:21 p.m.