I have the following table created using knitr::kable
Week Cost Disc total
Wk1 10000 -4000 6000
Wk2 20000 -3000 17000
Wk3 30000 -2000 28000
Wk4 40000 -1000 39000
I would like to display the numbers using an accounting format with a currency. I know you can use the paste function, but I was wondering if there is a cleaner solution. Here is how I would want it to look:
Week Cost Disc total
Wk1 $10,000 ($4,000) $6,000
Wk2 $20,000 ($3,000) $17,000
Wk3 $30,000 ($2,000) $28,000
Wk4 $40,000 ($1,000) $39,000
Any suggestions?
Using currency
in formattable
library:
##Your sample df
df <- data.frame(Week = c("Wk1", "Wk2", "Wk3", "Wk4"), Cost = c(10000, 20000, 30000, 40000))
library(formattable)
df$Cost <- currency(df$Cost, digits = 0L)
df
# Week Cost
#1 Wk1 $10,000
#2 Wk2 $20,000
#3 Wk3 $30,000
#4 Wk4 $40,000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With