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

*爱你&永不变心* 提交于 2019-12-01 15:12:55

问题


Currently, I have this data frame (PS):

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:

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

回答1:


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)


来源:https://stackoverflow.com/questions/44713731/r-knitrkable-how-to-display-table-without-column-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!