SFun28 SFun28 - 3 years ago 225
R Question

format numeric without leading zero

What's the best way to format a numeric so that it does NOT show leading zero. For example:

test = .006
sprintf/format/formatC( ??? ) # should result in ".006"

Answer Source

You can always fix it up yourself with regular expression search-and-replace:

test = .006
str_replace(as.character(test), "^0\\.", ".")

Not the most elegant answer, but it works. Substitute whatever string conversion you like for as.character, such as sprintf with your preferred floating point format.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download