how to control the decimal points in r, during the whole process

Viewed 46

how can I control the decimal point in r? Not only for printing but all the process.

options(digits=3) do not seems to work, because some of my statistics are 1000.9844 like this and some of my statistics are 0.3939 like this. I want to round it to the 4th digit, but if i use options(digits=4), 1000.9844 would be 1000.

1 Answers

I want to round it to the 4th digit, but if i use options(digits=4), 1000.9844 would be 1000.

You can use round(num, 4)

Eg,

> round(100.1234567, 4)
[1] 100.1235
> round(0.1234567, 4)
[1] 0.1235

However, as mentioned in the comment by @dww, this is not good practice since it can lead to the accumulation of rounding errors.

Related