Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

html - R Kable add_header_above adding line on blank spaces

I am unsure if I am doing anything wrong, but I am trying to create a table with a header that groups columns like below:

enter image description here

I followed the instructions provided in the documentation here, but I am still getting lines on the header cells that should be blank (first 2 columns). Below is the table I get after knitting to an html file. I am unsure how to troubleshoot.

enter image description here

Here is my reproducible table:

structure(list(sigma = c(0.321, 0.554, 0.483, 5.684, 8.824, 5.25
), R2 = c(94.47, 83.074, 86.853, 1.088, 13.921, 44.549), Linearity = c(8.38493902175155, 
7.74415836463606, 7.83262748829169, 3.58505816475888, 21.3428889807196, 
28.3052628262925), XLinearity = c(3.63637661675805, 3.35848314705469, 
3.39685039716013, 0.307760165986819, 1.83218535194569, 2.42987198125591
), Appraiser = c("AA", "AB", "AC", "AA", "AB", "AC"), Signal = c("Frequency", 
"Frequency", "Frequency", "Amplitude", "Amplitude", "Amplitude"
)), row.names = c(NA, 6L), class = "data.frame")

And my attempt:

GageResults$GageBiasAll%>%
    `colnames<-`(c("Value",rep(c("Bias","%Bias","$p$-value"),3)))%>%
  cbind(Signal=c(rep("Frequency",6),rep("Amplitude",6)),.)%>%
  kable(#caption = "Variation or each source of measurement error",
                     booktabs=T,row.names = F,
                     escape = T,digits = 3
                     )%>%
  # pack_rows("Frequency", 1, 6) %>%
  # pack_rows("Amplitude", 7, 12)%>%
  kable_styling(latex_options = c("striped","hold_position"))%>%
  collapse_rows(columns = 1, valign = "middle")%>%
  kable_classic(full_width = T, html_font = "Helvetica")%>%
  add_header_above(c(" "=2, "AA" = 3, "AB" = 3,"AC"=3))

And the result produced in the html file after knitting the markdown file. Again, I am trying to get rid with the line below the spaces that should be blank.

Thank you so much for the help!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I figured it out. The add_header_above() function has to come before te kable_styling function. Now it works perfectly. enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...