Issue
Looking for a easy method like EXCEL "Increase decimal","Decrease decimal"
# Example number
d <- c(0.6199548,0.8884106,0.9030066)
# Expected result :
[1]62% 89% 90%
# library scales result cannot adjust to 0 decimal
percent(d)
[1] "62.0%" "88.8%" "90.3%"
# Cannot handle sprinf() function well as weird result generated like below:
sprintf("%.1f %%", d)
[1] "0.6 %" "0.9 %" "0.9 %"
Do we have simple package to adjust the decimal percentage as easy as EXCEL in R?
Solution
Using round
and paste
:
d <- c(0.6199548,0.8884106,0.9030066)
paste0(round(d*100), "%")
[1] "62%" "89%" "90%"
Answered By - Tim Biegeleisen Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.