Format Specific Columns in kable

Viewed 402

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.

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()
Related