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:
- First, you need to install and load the
knitr
package, which provides thekable
function for creating tables in R.
install.packages("knitr")
library(knitr)
- Next, create a data frame or matrix representing your table data.
data <- data.frame(
Name = c("John", "Jane", "Mike"),
Amount = c(1000, 2500, 5000)
)
- Use the
format
function within thekable
call to format the numbers with a thousand mark. Theformat
function allows you to specify the desired formatting pattern using thebig.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.