Home > database >  Add thousand separator s to all columns of dataframe
Add thousand separator s to all columns of dataframe

Time:01-13

I have a dataframe with multiple numeric columns that need a thousand separator added to every column. Is there a simple way of doing this?

I have tried using mutate_all and prettyNum(var, big.mark=",") but I am an R newbie and can't figure out the syntax for just applying this across a whole dataframe. I have tried doing things like this:

    df <- df %>%
  mutate_all(prettyNum(var, big.mark = ","))

Any help appreciated.

CodePudding user response:

mutate_all was superseded. You can use across, by the default it will apply the function to all columns, but you can also use the argument .cols to set a specific group of variables to apply.

df %>% 
  mutate(across(.fns = ~prettyNum(., big.mark = ",")))
  • Related