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)
How can I avoid printing the column name?
You can also use kableExtra::remove_column() , to remove a selected column from your final kable table.
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.
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.")
The kableExtra package (Zhu 2021) is designed to extend the basic functionality of tables produced using knitr::kable() (see Section 10.1).
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?
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