Created
November 20, 2020 09:53
-
-
Save samclifford/58ac043f800623f94377df6d4ebde5f2 to your computer and use it in GitHub Desktop.
Trim trailing zeros from percentages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trim_percent <- function(x, ...){ | |
require(magrittr) | |
require(scales) | |
require(stringr) | |
scales::percent(x, ...) %>% | |
stringr::str_replace(string = ., pattern = "0+\\%", replacement = "\\%") %>% | |
stringr::str_replace(string = ., pattern = "\\.\\%", replacement = "\\%") | |
} |
Author
samclifford
commented
Nov 20, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment