R- knitr:kable - How to display table without column names?

Urvah Shabbir picture Urvah Shabbir · Jun 23, 2017 · Viewed 9.3k times · Source

Currently, I have this data frame (PS):

Table with column header

My code to display this table is:

kable(PS) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))

I want to display the table without column names like this: enter image description here

Problem is

1) The column names should be non-empty, and attempts to use empty names will have unsupported results

2) If I convert the data frame and remove the column names and then use kable like this:

PS.mat <- as.matrix(PS)
colnames(PS.mat) <- NULL
kable(PS) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))

I get the following error

Error in kable_info$colnames[[length(kable_info$colnames)]] : attempt to select less than one element in integerOneIndex

I also tried the following parameter but with no results

kable(PS, col.names = NA) 

EDIT 1:

A reproducible example:

if (!require(pacman)) install.packages("pacman")
p_load("lubridate","knitr","kableExtra","scales")

Statistics <- c("AUM",
            "Minimum Managed Account Size",
            "Liquidity",
            "Average Margin / Equity",
            "Roundturns / $ Million / Year",
            "Incentive Fees",
            "Instruments Traded")
Value <- c("$30K","$30K","Daily","50%","6,933","25%","ES")
AI <- data.frame(Statistics,Value);
kable(AI) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))

Answer

Jan picture Jan · Jun 23, 2017

Depending on your desired output format you could make use of such functions. For pandoc:

x = kable(AI, format="pandoc") %>%
    kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
cat(x[3:9], sep="\n")

For html:

x = kable(AI, format="html") %>%
    kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
gsub("<thead>.*</thead>", "", x)