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?

2 Answers

5
Tim Biegeleisen On Best Solutions

Using round and paste:

d <- c(0.6199548,0.8884106,0.9030066)
paste0(round(d*100), "%")

[1] "62%" "89%" "90%"
4
Gregor On

I'd suggest looking at the documentation of ?percent before you decide what it can and can't do.

# library scales result cannot adjust to 0 decimal
## OR CAN IT
percent(d, 1)
[1] "62%" "89%" "90%"

From the help page ?percent:

percent(x, accuracy = NULL, scale = 100, prefix = "",
  suffix = "%", big.mark = " ", decimal.mark = ".", trim = TRUE,
  ...)
# ...
# accuracy  Number to round to, NULL for automatic guess.