9

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"))
Urvah Shabbir
  • 945
  • 2
  • 15
  • 46
  • Can you make your example reproducible? – Roman Luštrik Jun 23 '17 at 05:51
  • @RomanLuštrik. added the example. – Urvah Shabbir Jun 23 '17 at 05:55
  • Sorry for the wrong edit. Updated again with a simple data frame. – Urvah Shabbir Jun 23 '17 at 05:58
  • Does your sample code work on your machine? Because when I try to reproduce your error, it works fine after I figure out which libraries you are referring to (answer: `knitr` and `kableExtra`, and the `%>%` pipe can be found in `magrittr` or `dplyr`) – lebelinoz Jun 23 '17 at 06:19
  • I am so sorry I forgot to add the libraries. My code uses all these libraries: ("xlsx","lubridate","gridExtra","ggplot2","knitr","kableExtra","scales","plyr","plotly") But for above mentioned code snippet knitr and kableExtra would be enough I guess. – Urvah Shabbir Jun 23 '17 at 06:25
  • @jan. thankyou for reading the question and suggesting an edit. But here `library(pacman)` is not required because it already is done when `if(!require(pacman))` is run. – Urvah Shabbir Jun 23 '17 at 07:56

1 Answers1

12

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)
Jan
  • 3,825
  • 3
  • 31
  • 51
  • @urwaCFC: would you mind to mark the question as answered? thanks! – Jan Jun 24 '17 at 19:22
  • I thought I did. I had only upvoted. I have marked it as answered. Thanks once again. – Urvah Shabbir Jun 24 '17 at 22:10
  • Can you please answer this question: It is a variant of above question. https://stackoverflow.com/questions/44748726/r-knitrkable-removing-individual-headers-and-adding-single-header-on-multip Thanks. – Urvah Shabbir Jun 25 '17 at 17:35