Use formatC
:
formatC(a, width=10, drop0trailing=TRUE)
[1] " 18.12" " 0" " 1.5" " 34.12" " 2.1"
To paste
into a single string, use the argument collapse=""
:
paste0(formatC(a, width=10, drop0trailing=TRUE), collapse="")
[1] " 18.12 0 1.5 34.12 2.1"
To left justify, use the argument flag="-"
:
formatC(a, width=10, drop0trailing=TRUE, flag="-")
[1] "18.12 " "0 " "1.5 " "34.12 " "2.1 "
See ?formatC
, ?prettyNum
or ?format
for more help and other options.