Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounding to 2 decimal places whilst retaining scientific notation in R

Tags:

rounding

r

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?

like image 476
Lynsey Avatar asked Nov 28 '22 06:11

Lynsey


2 Answers

Try

signif(2.60699382414341e-56, digits=3)

# 2.61e-56
like image 143
shitoushan Avatar answered Dec 15 '22 10:12

shitoushan


Use format:

> P = 2.60699382414341e-56
> format(P, digits=3)
[1] "2.61e-56"
like image 33
Matt Avatar answered Dec 15 '22 11:12

Matt