简体   繁体   中英

Removing column names in pandoc table - r markdown

Is it possible to remove (not to show) column names in pandoc tables?
If I use pander (or pandoc.table ) function it prints column names automatically.

> pander(iris[1:4, ])

-------------------------------------------------------------------
 Sepal.Length   Sepal.Width   Petal.Length   Petal.Width   Species 
-------------- ------------- -------------- ------------- ---------
 5.1            3.5           1.4            0.2       setosa  

 4.9             3            1.4            0.2       setosa  

 4.7            3.2           1.3            0.2       setosa  

 4.6            3.1           1.5            0.2       setosa  
-------------------------------------------------------------------

Expected output should be:

-------------------------------------------------------------------
                                         
-------------- ------------- -------------- ------------- ---------
 5.1            3.5           1.4            0.2       setosa  

 4.9             3            1.4            0.2       setosa  

 4.7            3.2           1.3            0.2       setosa  

 4.6            3.1           1.5            0.2       setosa  
-------------------------------------------------------------------

I'd fix this outside of pander by simply removing the column headers:

> df <- iris[1:4, ]
> names(df) <- NULL
> pander(df)

--- --- --- --- ------
5.1 3.5 1.4 0.2 setosa

4.9  3  1.4 0.2 setosa

4.7 3.2 1.3 0.2 setosa

4.6 3.1 1.5 0.2 setosa
--- --- --- --- ------

Would this suffice?

pandoc.table({temp <- iris; names(temp) <- rep(" ", ncol(temp)); temp[1:4,]})

to yield.

----------------------

--- --- --- --- ------
5.1 3.5 1.4 0.2 setosa
4.9  3  1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
----------------------

I'd replace Benjamin's &nbsp with NULL but otherwise agree:

temp <- iris[1:4,]; names(temp) <- rep(NULL, ncol(temp)); temp[1:4,] 
pandoc.table(temp)

setting column names to NULL like so names(dt) <- NULL actually gives an error. In my case

Error in alloc.col(newx) : Internal error: length of names (0) is not length of dt (2)

using a data.table with 2 columns.

Instead, I'd go with

names(dt) <- rep(" ", ncol(dt)) pander(dt)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM