hamagust
hamagust

Reputation: 856

different total number of columns in add_header_above from kable

I am using kableExtra to format tables in rmarkdown. In one of my dataframes I am obtaining a strange result...

ncol(Selected)
Selected%>%
kable("html",format.args = list(decimal.mark = ".", big.mark = ","),caption = "Variables description  and data cleaning and treatment summary") %>%
add_header_above(c(" " = 2, "Kolmogorov-Smirnov" = 2, "Kruskall-Wallis" = 2, "Wilcoxon  Test"= 2)) %>%
kable_styling()

The object Selected is a dataframe, with dimension (256;8)...

I got this:

[1] 8
Error in htmlTable_add_header_above(kable_input, header, bold, italic, : The new header row you provided has a different total number of columns with the original kable output.

What is wrong? By ncol, I confirmed the object Selected has 8 columns... Thanks in advance.

Upvotes: 1

Views: 2053

Answers (1)

hamagust
hamagust

Reputation: 856

This data frame has row names. The kable command counts row names as the column. Counting this, it worked.

Selected%>%
kable("html",format.args = list(decimal.mark = ".", big.mark = ","),caption = "Variables description  and data cleaning and treatment summary") %>%
add_header_above(c(" " = 3, "Kolmogorov-Smirnov" = 2, "Kruskall-Wallis" = 2, "Wilcoxon  Test"= 2)) %>%
kable_styling()

Upvotes: 3

Related Questions