kable thousand mark

To add a thousand mark to numbers in a table generated using the kable function in R, you can use the format function within the kable call. Here are the steps to achieve this:

  1. First, you need to install and load the knitr package, which provides the kable function for creating tables in R.
install.packages("knitr")
library(knitr)
  1. Next, create a data frame or matrix representing your table data.
data <- data.frame(
  Name = c("John", "Jane", "Mike"),
  Amount = c(1000, 2500, 5000)
)
  1. Use the format function within the kable call to format the numbers with a thousand mark. The format function allows you to specify the desired formatting pattern using the big.mark argument.
kable(data, format = "html", digits = 0, col.names = c("Name", "Amount"), align = "c") %>%
  kable_styling()

In the above code, the format argument is set to "html" to generate an HTML table. The digits argument is set to 0 to remove any decimal places from the numbers. The col.names argument is used to specify the column names for the table. The align argument is set to "c" to center-align the table content.

By default, the big.mark argument in the format function uses a comma (",") as the thousand mark. If you want to use a different character as the thousand mark, you can specify it using the big.mark argument.

That's it! The resulting table will display the numbers with a thousand mark, making it easier to read and understand the values.