How to disable scientific notation?

RFormattingScientific Notation

R Problem Overview


I have a dataframe with a column of p-values and I want to make a selection on these p-values.

> pvalues_anova
[1] 9.693919e-01 9.781728e-01 9.918415e-01 9.716883e-01 1.667183e-02
[6] 9.952762e-02 5.386854e-01 9.997699e-01 8.714044e-01 7.211856e-01
[11] 9.536330e-01 9.239667e-01 9.645590e-01 9.478572e-01 6.243775e-01
[16] 5.608563e-01 1.371190e-04 9.601970e-01 9.988648e-01 9.698365e-01
[21] 2.795891e-06 1.290176e-01 7.125751e-01 5.193604e-01 4.835312e-04

Selection way:

anovatest<- results[ - which(results$pvalues_anova < 0.8) ,]

The function works really fine if I use it in R. But if I run it in another application (galaxy), the numbers which don't have e-01 e.g. 4.835312e-04 are not thrown out.

Is there another way to notate p-values, like 0.0004835312 instead of 4.835312e-04?

R Solutions


Solution 1 - R

You can effectively remove scientific notation in printing with this code:

options(scipen=999)

Solution 2 - R

format(99999999,scientific = FALSE)

gives

99999999

Solution 3 - R

I also find prettyNum(..., scientific = FALSE) function useful for printing when I don't want trailing zeros. Note that these functions are useful for printing purposes, i.e. the output of these functions are strings, not numbers.

p_value <- c(2.45496e-5, 3e-17, 5.002e-5, 0.3, 123456789.123456789)
format(p_value, scientific = FALSE)
#> [1] "        0.00002454960000000" "        0.00000000000000003"
#> [3] "        0.00005002000000000" "        0.29999999999999999"
#> [5] "123456789.12345679104328156"


format(p_value, scientific = FALSE, drop0trailing = TRUE)
#> [1] "        0.0000245496"        "        0.00000000000000003"
#> [3] "        0.00005002"          "        0.29999999999999999"
#> [5] "123456789.12345679104328156"


# Please note that the last number's last two digits are rounded:
prettyNum(p_value, scientific = FALSE, digits = 16)
#> [1] "0.0000245496"        "0.00000000000000003" "0.00005002"         
#> [4] "0.3"                 "123456789.1234568"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSamanthaView Question on Stackoverflow
Solution 1 - RSacha EpskampView Answer on Stackoverflow
Solution 2 - RPeterView Answer on Stackoverflow
Solution 3 - RHBatView Answer on Stackoverflow