Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add commas every digits in numbers of kable()

I have the dataframe below and I create a kable out of this. How could I add commas between numbers every 3 digits?

Descs<-structure(list(Mean = c(NaN, 943330388, NaN, NaN, NaN, 543234645, 
45831420, NaN, 27301292, 160818771), Median = c(NaN, 943330388, 
NaN, NaN, NaN, 543234645, 45831420, NaN, 27301292, 160818771), 
    SD = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), MAD = c(NA, 
    0, NA, NA, NA, 0, 0, NA, 0, 0), MIN = c(NA, 943330388, NA, 
    NA, NA, 543234645, 45831420, NA, 27301292, 160818771), MAX = c(NA, 
    943330388, NA, NA, NA, 543234645, 45831420, NA, 27301292, 
    160818771), VAR = c(NA_real_, NA_real_, NA_real_, NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
    ), RANGE = structure(c(NA, 943330388, NA, NA, NA, 543234645, 
    45831420, NA, 27301292, 160818771, NA, 943330388, NA, NA, 
    NA, 543234645, 45831420, NA, 27301292, 160818771), .Dim = c(10L, 
    2L)), QUANTILES = structure(c(NA, 943330388, NA, NA, NA, 
    543234645, 45831420, NA, 27301292, 160818771, NA, 943330388, 
    NA, NA, NA, 543234645, 45831420, NA, 27301292, 160818771), .Dim = c(10L, 
    2L), .Dimnames = list(NULL, c("25%", "75%")))), row.names = c("Comedy", 
"Education", "Entertainment", "Film & Animation", "Gaming", "Howto & Style", 
"Music", "People & Blogs", "Science & Technology", "Sports"), class = "data.frame")

library(kableExtra)

kable(Descs) %>%
    kable_styling(
      font_size = 15,
      bootstrap_options = c("striped", "hover", "condensed")
    ) 

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could use the kable format argument, this avoids mucking around with the data prior to putting into the table.

And if you want to clear up the NAs and NaNs you could add in this line of code: options(knitr.kable.NA = '')

library(kableExtra)

kable(Descs,
      format.args = list(big.mark = ",")) %>%
  kable_styling(
    font_size = 15,
    bootstrap_options = c("striped", "hover", "condensed")
  ) 

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading