0

I have a dataframe with numbers. I need to format it by adding commas.

df
ColA   ColB
sd     68900744.0
fg     78900744.0
gh     88900744.0
fg     1375292.0

Expected output

df
ColA   ColB
sd     68,900,744
fg     78,900,744
gh     88,900,744
fg     1,375,292
Dave2e
  • 22,192
  • 18
  • 42
  • 50
imran p
  • 332
  • 2
  • 12

1 Answers1

0

For more information see ?formatC

  df$ColB_new <- formatC(df$ColB, format="f", big.mark=",", digits=0)

for alternative options see Format number in R with both comma thousands separator and specified decimals or Comma separator for numbers in R?

jyr
  • 690
  • 6
  • 20