I would like R to display floating point numbers only a small amount of digits after the decimal dot. much like "format short" would do in matlab.
Is there a simple way to do that?
I would like R to display floating point numbers only a small amount of digits after the decimal dot. much like "format short" would do in matlab.
Is there a simple way to do that?
You can either use an ad-hoc conversion through either formatC, sprintf or format
?formatC
formatC(.000000012, format='fg')
[1] "0.000000012"
?sprintf
sprintf("%.10f", 0.0000000012)
[1] "0.0000000012"
format(.0000012, scientific=FALSE)
[1] "0.0000012"
or you set the digits option:
options(digits=10)
or the scipen option:
options(scipen=10)
Just use options("digits"=someSmallNumber)
. Here is an example using the default and then the value two:
R> set.seed(42); data.frame(a=rnorm(3), b=runif(3))
a b
1 1.370958 0.736588
2 -0.564698 0.134667
3 0.363128 0.656992
R>
R> options("digits"=2)
R> set.seed(42); data.frame(a=rnorm(3), b=runif(3))
a b
1 1.37 0.74
2 -0.56 0.13
3 0.36 0.66
R>