Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove/hide column names in kable?

I am plotting a table using following code but I found there is unnecessary column names V1 and V2 appear as column name.

statdat<-read.table("stat.txt",sep="\t",header=FALSE)
kable(statdat) 

enter image description here

How can I avoid printing the column name?

like image 430
Manish Avatar asked Jul 18 '18 10:07

Manish


People also ask

How do you delete a column in Kable?

You can also use kableExtra::remove_column() , to remove a selected column from your final kable table.

How do I remove a column name in R?

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.

How do you put a title on a Kable table?

You can add a caption to the table via the caption argument, e.g. (see Table 10.1 for the output), knitr::kable(iris2, caption = "An example table caption.")

What R package is Kable in?

The kableExtra package (Zhu 2021) is designed to extend the basic functionality of tables produced using knitr::kable() (see Section 10.1).


1 Answers

You can set col.names to NULL to remove the column names:

kable(statdat, col.names = NULL) 

An alternative solution is to use format="pandoc" and cat() to select the relevant rows after the table has been created. This solution is given here: R- knitr:kable - How to display table without column names?

like image 157
Martin Avatar answered Sep 30 '22 00:09

Martin