For specifying the number of digits, tipically we use the command round, for example:
round(pi, digits=2)
[1] 3.14
However, we can also use sprintf
command to deal with both the number of digits and the + or – in your equation, for example:
sprinf(“%3.2f”,pi)
[1] “3.14”
Note that,
forces the + or – sign in a equation.3.2f
controls the number of digits and the symbol %
No comments