0

Is there any way of limiting the number of digits R displays in any context? I have tried everything, including options(digits = 3).

Take a look at this output from my code (after calling options(digits = 3)):

compute(NN, cbind(Test_cv[,c("Activity", "Annualised_15")], (Test_cv[, "Activity"]^2), (Test_cv[, "Annualised_15"]^2) ) )

Output:

$neurons[[2]]
    [,1]      [,2]     [,3]                                                                                                        [,4]
12     1 0.9999202 0.000015 0.000000000000000005288370990993990868565821639180057900375686585903167724609375000000000000000000000000000
13     1 0.9991250 0.619258 0.000000000000013876853661493364176966747169927884897333569824695587158203125000000000000000000000000000000
35     1 0.0000727 0.003018 0.032829945321210009245849192893729195930063724517822265625000000000000000000000000000000000000000000000000

Columns two and three are already too much, but column four is just insane!

scipen is not what I want either - setting it to low values gives me scientific notation:

options(scipen = 2, digits = 3)
compute(NN, cbind(Test_cv[,c("Activity", "Annualised_15")], (Test_cv[, "Activity"]^2), 
                  (Test_cv[, "Annualised_15"]^2)  ) )

Output:

    [,1]      [,2]     [,3]      [,4]   
12     1 0.9999202 0.000015  5.29e-18 
13     1 0.9991250 0.619258  1.39e-14

I just want this:

    [,1]      [,2]     [,3]      [,4]   
12     1      0.99     0.00      0.00 
13     1      0.99     0.62      0.00

Anywhere, any time.

How do I limit this at the start of the session to stop this happening anywhere at any time without having to use round() or signif() or sprintf() or formatC() all the time and wrapping every single piece of code in one of these functions?

p.s. I haven't included a reproducible example because I'm sure lots of people have seen this kind of thing and it's a very general question.

Many, many thanks to anyone who can answer this.

Luther_Blissett
  • 327
  • 1
  • 6
  • 16
  • 1
    Probably `sprintf("%0.2f", 0.00000000000000000528837)` will work if it's just for display. This function returns a character vector. Or the related `formatC(0.00000000000000000528837, digits=2, format="f")`. – lmo Mar 17 '17 at 12:27
  • I'm looking for a UNIVERSAL solution so that I don't have to keep wrapping my code in those kind of one-off functions like formatC() or sprintf(). Surely I can, at the start of the session just call a function that goes I_Only_Want_to_see_x_Numbers(3) and I don't have to worry about it for the rest of the script/session. – Luther_Blissett Mar 17 '17 at 12:40

0 Answers0