phsmethods
phsmethods copied to clipboard
Add thousands separator (function)
Opening this to suggest including a function that adds a thousands separator to numbers.
add_thousands_sep <- function(x){ gsub("(?!^)(?=(?:\\d{3})+$)", ",", x, perl = TRUE) }
This essentially adds a thousands separator for pretty formatting of numbers, including character vectors that contain numbers. The regex itself could use improvement though but overall handy when some of your numbers are character vectors.