R Markdown kable table using $ sign in column name for html output

Viewed 309

I'm wanting to include the units in my column description for a kable table in R Markdown with html output. Basically for each cost I want 'Cost Min ($k)', 'Cost Mode ($k)' and 'Cost Max ($k)' as 3 of my column names.

It works fine for my first table but then for my second it is outputting it with strange formatting and not reading each column name correctly.

html output

My code is as follows:


Summary<- matrix(c(0.90,0.99,1000,3000,5000,0.90,0.99,1000,3000,5000,0.30,0.60,500,750,1000), ncol=5,byrow=TRUE)

colnames(Summary)<-c("Probability Lower","Probability Upper" , "Cost Min ($k)" , "Cost Mode ($k)" , "Cost Max ($k)")
rownames(Summary)<-c("Start", "Current", "Target")
SummaryTable<-as.table(Summary)

knitr::kable(SummaryTable, format = "html") %>%
  kableExtra::kable_styling(SummaryTable,bootstrap_options = "bordered")

Any help would be much appreciate as I would like all my tables to look like the one that is working.

Laura

1 Answers

Try using two backslashes before the dollar sign, like this: \\$:

colnames(Summary)<-as.character(c("Probability Lower","Probability Upper" , "Cost Min (\\$k)" , "Cost Mode (\\$k)" , "Cost Max (\\$k)"))
rownames(Summary)<-c("Start", "Current", "Target")

enter image description here

Related