7

I am sinking output from a linear model, and trying to tidy it up as it is sinked by rounding the parameters I am interested in to 2 decimal places. This is fine for most parameters like beta or Z-score, but I am having difficulty with P-value. As although I do want to round to 2 decimal places, I mean 2 decimal places whilst retaining scientific notation.

For example:

P = 2.60699382414341e-56

round(P,2)

#[1] 0

When really what I want to print is :

#2.61e-56

Is there a means of doing this?

M--
  • 25,431
  • 8
  • 61
  • 93
Lynsey
  • 339
  • 1
  • 2
  • 11
  • See here: https://stackoverflow.com/questions/3443687/formatting-decimal-places-in-r – Florian Jul 14 '17 at 14:58
  • I think what you want to do is `round(P, 58)` (but the answers below are better) – Ettore Rizza Jul 14 '17 at 14:58
  • Thank you for the rapid response! I had looked at other questions, but they were generally regarding NOT using scientific notation. All of these answers work, so what is the convention for the "accepted answer" in this instance? – Lynsey Jul 14 '17 at 15:04
  • Don't know. :/ The fastest ? – Ettore Rizza Jul 14 '17 at 15:20

3 Answers3

20

Try

signif(2.60699382414341e-56, digits=3)

# 2.61e-56
shitoushan
  • 458
  • 3
  • 11
7

Use format:

> P = 2.60699382414341e-56
> format(P, digits=3)
[1] "2.61e-56"
Matt
  • 954
  • 1
  • 9
  • 24
2

This right here:

> P = 2.60699382414341e-56
> options("scipen"=2, "digits"=3)
> P
[1] 2.61e-56

See also: Force R not to use exponential notation (e.g. e+10)?

cremorna
  • 374
  • 1
  • 9