我喜欢使用结果的ascii输出。
我的表格标题中总是有一个额外的'h',我手动删除。
我不知道如何在我的代码中修复它。查看代码和结果。例如,有多少汽车有多少个cilinders。
data(mtcars)
library(ascii)
ascii(as.data.frame(table(mtcars$cyl)),include.rownames=F,format='nice')
|================
h| Var1 h| Freq
| 4 | 11
| 6 | 7
| 8 | 14
|================
我想从标题中删除多余的h字符。所以输出看起来像这样:
|================
| Var1 | Freq
| 4 | 11
| 6 | 7
| 8 | 14
|================
是ascii库还是我的代码中的错误? 我想通过ascii调用的正确参数来做,而不是后处理输出,但是如果不能使用正确的解决方案,则会考虑任何“修复”。
答案 0 :(得分:2)
这并不完全明显,但ascii.data.frame
函数采用header
参数,当设置为FALSE时将消除不需要的“h”。还有一个include.colnames
参数,如果想要摆脱我所谓的“标题”。
> ascii(as.data.frame(table(mtcars$cyl)),include.rownames=F,header=FALSE,format='nice')
|==============
| Var1 | Freq
| 4 | 11
| 6 | 7
| 8 | 14
|==============