简体   繁体   中英

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

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.

输出

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

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")

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM