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"))
Function 'kable()' is a light weight table generator coming from 'knitr'. This package simplifies the way to manipulate the HTML or 'LaTeX' codes generated by 'kable()' and allows users to construct complex tables and customize styles using a readable syntax.
In R, the easiest way to remove columns from a data frame based on their name is by using the %in% operator. This operator lets you specify the redundant column names and, in combination with the names() function, removes them from the data frame. Alternatively, you can use the subset() function or the dplyr package.
By defining the table format and adding some CSS styling you can change the size of the like so: knitr::kable(x, format = "html", table. attr = "style='width:30%;'") .
The kable() function in knitr is a very simple table generator, and is simple by design. It only generates tables for strictly rectangular data such as matrices and data frames. You cannot heavily format the table cells or merge cells.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With