Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a problem in rounding numbers in R. I have the following data, and I want to round them to 8 decimal digits.

structure(c(9.50863385275955e-05, 4.05702267762077e-06, 2.78921491976249e-05, 
8.9107773737659e-05, 5.0672643927135e-06, 5.87776809485182e-05,
2.76421630542694e-05, 5.51662570625727e-05, 2.52790624570593e-05, 
2.00407457671806e-05, 8.33373482160056e-05, 7.8297940825207e-05,
2.00407457671806e-05, 8.33373482160056e-05, 7.8297940825207e-05,
2.00407457671806e-05, 8.33373482160056e-05, 7.8297940825207e-05
), .Names = c("CC/CC", "TT/CC", "CT/CC", "NC/CC", "CC/TT", "TT/TT",
"CT/TT", "NC/TT", "CC/CT", "TT/CT", "CT/CT", "NC/CT"))

These digits are in the form of exponent and I want to convert them to rational numbers with 8 decimal places.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
385 views
Welcome To Ask or Share your Answers For Others

1 Answer

For fine control over formatting of numbers, try formatC()

res <- structure(c(9.50863385275955e-05, 4.05702267762077e-06), 
                 .Names = c("CC/CC", "TT/CC"))

formatC(res, format="f", digits=8)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...