删除 pandoc table 中的列名 - r markdown

Removing column names in pandoc table - r markdown

是否可以删除(不显示)pandoc 表中的列名?
如果我使用 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  
-------------------------------------------------------------------

预期输出应为:

-------------------------------------------------------------------
                                         
-------------- ------------- -------------- ------------- ---------
 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  
-------------------------------------------------------------------

这就够了吗?

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

屈服。

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

--- --- --- --- ------
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
----------------------

我会将 Benjamin 的   替换为 NULL,否则同意:

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

我会在 pander 之外解决这个问题,只需删除列 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
--- --- --- --- ------

将列名设置为 NULL 像这样 names(dt) <- NULL 实际上会出错。就我而言

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

使用具有 2 列的 data.table

相反,我会选择

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