PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 11, 2022

[FIXED] How to round up percentage in 0 decimal in R

 August 11, 2022     decimal, format, percentage, r, rounding     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing