How to format output of R?

You can use R command format. For example

    round(0.10000, 3)

produces

0.1

instead of

0.100

. To get correct format, we can use the following command

    format(round(0.10000,3), nsmall=3, digits=3)

Note that the return value of the above command is a character string "0.100", not a numerical value.

FAQ Category