[R] default print format for large numbers
Richard.Cotton at hsl.gov.uk
Richard.Cotton at hsl.gov.uk
Wed Apr 8 16:47:44 CEST 2009
> Numbers like ``1239178547.653775" is inserted into a vector. I print
> the vector:
>
> > route_9_80_end
> [1] 1239178522 1239178526 1239178524 1239178524 1239178524
> 1239178523 1239178524 1239178522 1239178521 1239178565 1239178566
1239178566
> [13] 1239178565 1239178566 1239178566 1239178565 1239178566 1239178566
>
> and the decimals are suppressed. While R is wonderful and
> wonderfully documented, I can only find some quasi relavent
> information on options(digits) or some such as might apply here. How
> can I force R to print some part of the decimal i.e. back to
> 1239178547.653775?
When you create the vector, each number is stored as a double-precision
floating point number. When you type the name of the variable the print
function is called, which displays the numbers on the console.
You can also manually call the print function, and set the digits argument
to a high number to show all digits.
If you want to see all the digits every time any number is displayed, use
options(digits).
For example:
x <- 1239178547.653775
x
# [1] 1239178548
print(x)
# [1] 1239178548
print(x, digits=20)
# [1] 1239178547.653775
options(digits=20)
x
# [1] 1239178547.653775
Note that the accuracy of the floating point numbers is limited to
.Machine$double.eps, which is typically 2.2e-16.
Regards,
Richie.
Mathematical Sciences Unit
HSL
------------------------------------------------------------------------
ATTENTION:
This message contains privileged and confidential inform...{{dropped:20}}
More information about the R-help
mailing list