Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format Specific Columns in kable

Suppose I want to format the dataset mtcars as a kable table

kable(mtcars*100)

I want to add a "," for the after each 1000 in the "hp" column (1,000 instead of 1000), but I do not want "," separator in any other column.

Right now I am using:

kable(mtcars,format.args=list(big.mark=","))

What I want to do is control specifically which columns have the comma delimiter and which do not.

like image 557
Mark Avatar asked Aug 27 '26 10:08

Mark


1 Answers

I'm not sure if this is what you want:

library(dplyr)
library(knitr)

df %>% 
  mutate(across(hp, ~ format(.x, big.mark = ","))) %>% 
  kable()
like image 56
Anoushiravan R Avatar answered Aug 30 '26 01:08

Anoushiravan R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!