1

Suppose I have

 a = c("88", "haha", NA, "8,888", "2.4k")

I want to reformat the numbers to

 88, NA, NA, 8888, 24000

I read a post about formatting, but still do not understand how to do this.. Format number in R with both comma thousands separator and specified decimals

Community
  • 1
  • 1
user3697665
  • 297
  • 1
  • 6
  • 17
  • Not exactly the same but worth mention is John Fox's work in R News from 10 years ago: pages 51-53 of http://cran.r-project.org/doc/Rnews/Rnews_2005-1.pdf – IRTFM Dec 05 '15 at 07:04
  • If you want an out-of-the-box solution, you can also check out the `readr` package, which has `parse_number` function which can handle currencies as well as the comma separator, but it doesn't handle the `2.4k` case... – chappers Dec 05 '15 at 07:11
  • @TheTime Thanks! and I think it should be 'e3' in the sub instead of 'e4'? – user3697665 Dec 05 '15 at 22:08

0 Answers0