phsmethods icon indicating copy to clipboard operation
phsmethods copied to clipboard

Add thousands separator (function)

Open Nic-Chr opened this issue 3 years ago • 3 comments

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.

Nic-Chr avatar May 22 '21 16:05 Nic-Chr