简体   繁体   English

删除 pandoc 表中的列名 - r markdown

[英]Removing column names in pandoc table - r markdown

Is it possible to remove (not to show) column names in pandoc tables?是否可以删除(不显示)pandoc 表中的列名?
If I use pander (or pandoc.table ) function it prints column names automatically.如果我使用pander (或pandoc.table )功能,它会自动打印列名。

> 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:我想解决这个问题之外pander通过简单地移除列标题:

> 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:我会用 NULL 替换本杰明的 &nbsp ,但否则同意:

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.像这样将列名设置为NULL names(dt) <- NULL实际上会产生错误。 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.使用具有 2 列的data.table

Instead, I'd go with相反,我会去

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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