其他格式的 CrossTable 函数
CrossTable function in other formatting
有没有办法将使用 Crosstable 函数创建的 table 输出转换为另一种格式?
我试过使用 xtable
library(gmodels)
library(descr)
TB14.4 =CrossTable(AvaliacaoEAD,instrucao,prop.r=TRUE, prop.c=TRUE,
prop.t=FALSE, prop.chisq=FALSE, format="SPSS" )
install.packages("xtable")
library(xtable)
xtable(TB14.4)
错误如下:
Error in UseMethod ("xtable"):
method not applicable for 'xtable' applied to an object of class "list"
由 descr
包生成的 CrossTable
对象更灵活,无论您是要存储 CrossTable
输出还是计算内容。例如,这个 R Markdown 文档:
---
title: "CrossTable Example"
output: html_document
---
<style>
.main-container {
max-width: 940px;
margin-left: 0;
margin-right: auto;
}
</style>
```{r example, echo=FALSE, message=FALSE}
library(descr)
library(pander)
my.table <- descr::CrossTable(mtcars$cyl, mtcars$mpg, prop.r=TRUE, prop.c=TRUE, prop.t=FALSE, prop.chisq=FALSE, format="SPSS")
class(my.table)
pander(my.table)
```
生成类型为 CrossTable
的对象,即使对于大量列,也很容易被 pander
格式化。请注意,此时您可以选择通过将 prop
中的一个或多个设置为 FALSE
来使其更易于阅读。
有没有办法将使用 Crosstable 函数创建的 table 输出转换为另一种格式?
我试过使用 xtable
library(gmodels)
library(descr)
TB14.4 =CrossTable(AvaliacaoEAD,instrucao,prop.r=TRUE, prop.c=TRUE,
prop.t=FALSE, prop.chisq=FALSE, format="SPSS" )
install.packages("xtable")
library(xtable)
xtable(TB14.4)
错误如下:
Error in UseMethod ("xtable"):
method not applicable for 'xtable' applied to an object of class "list"
由 descr
包生成的 CrossTable
对象更灵活,无论您是要存储 CrossTable
输出还是计算内容。例如,这个 R Markdown 文档:
---
title: "CrossTable Example"
output: html_document
---
<style>
.main-container {
max-width: 940px;
margin-left: 0;
margin-right: auto;
}
</style>
```{r example, echo=FALSE, message=FALSE}
library(descr)
library(pander)
my.table <- descr::CrossTable(mtcars$cyl, mtcars$mpg, prop.r=TRUE, prop.c=TRUE, prop.t=FALSE, prop.chisq=FALSE, format="SPSS")
class(my.table)
pander(my.table)
```
生成类型为 CrossTable
的对象,即使对于大量列,也很容易被 pander
格式化。请注意,此时您可以选择通过将 prop
中的一个或多个设置为 FALSE
来使其更易于阅读。