Monday, November 26, 2012

How to change numerical values from scientific to standard notation in R

It happened to me that i have imported a datasheet into R with read.table and one of the columns was not in a standard decimal but in a scientific notation.

comp_rn_rnra <- read.table("rn_rn+ra_Galaxy8-[Concatenate_datasets_on_data_5_and_data_7](1).tabular")

The data from column 18th was in a scientific format:

 comp_rn_rnra [,18]

...

[9961] -2.733851e+00 -2.927036e+00 -2.675253e+00 -2.007405e+00 -2.049330e+00
[9966] -1.604401e+00 -1.940523e+00 -4.006117e+00 -4.449443e+00 -2.298376e+00
[9971] -2.298376e+00 -6.736356e+00 -3.351846e+00 -1.122227e+01 -1.873104e+00
[9976] -5.679507e+00 -2.303457e+00 -2.079998e+04 -2.694311e+00 -1.539045e+00
[9981] -4.985677e+00 -5.308146e+00 -2.291038e+00 -1.578426e+00 -2.274986e+00
[9986] -2.439064e+01
>

How to change it back to a standard decimal notation?

Type:

options (scipen=10)

Now print 18th column:

comp_rn_rnra [,18] 

...

[9961]      -2.733851      -2.927036      -2.675253      -2.007405
[9965]      -2.049330      -1.604401      -1.940523      -4.006117
[9969]      -4.449443      -2.298376      -2.298376      -6.736356
[9973]      -3.351846     -11.222271      -1.873104      -5.679507
[9977]      -2.303457  -20799.979589      -2.694311      -1.539045
[9981]      -4.985677      -5.308146      -2.291038      -1.578426
[9985]      -2.274986     -24.390642
>

To revert to scientific type:

options (scipen=0)

No comments:

Post a Comment