0

I noticed that if you are printing a vector of percentages that are on the same order of magnitude, percent() works well in getting you three significant digits.

> library(scales)
> percent(c(0.123,0.234))
[1] "12.3%" "23.4%"

>percent(c(0.00123,0.00234))
[1] "0.123%" "0.234%"

But if your percentages are of different orders of magnitude, percent will pick the precision that works for the largest element -- not helpful in my use case.

> percent(c(0.123,0.00234))
[1] "12.3%" "0.2%" 

How can I get three significant figures for each percent when they are of different orders of magnitude?

C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134

2 Answers2

0

You can use sapply() to consider each element separately.

> sapply(c(0.123,0.00234), percent)
[1] "12.3%"  "0.234%"
C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
0

percent only allows you to see up to 3 digits, but if you want more digits, what you can do is:

> test <- c(123.46644, 139.23424646)
> test <- paste(test*100, "%", sep = "")
> test
[1] "12346.644%"    "13923.424646%"
jeron
  • 92
  • 10