【问题标题】:CrossTable function in other formatting其他格式的 CrossTable 函数
【发布时间】:2020-05-09 20:31:17
【问题描述】:

有没有办法将使用 Crosstable 函数创建的表格输出转换为另一种格式?

我尝试使用 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"

【问题讨论】:

    标签: r xtable


    【解决方案1】:

    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 来使其更易于阅读。

    【讨论】:

    • 完美!成功了,非常感谢!有没有办法把标题和字体放在这个包里?
    • 是的,您可以自定义 R Markdown 中的所有字体(请参阅rmarkdown.rstudio.com/authoring_quick_tour.html)。如果这有助于您解决问题,您是否可以检查以接受答案?谢谢...很高兴它对您有用。
    猜你喜欢
    • 1970-01-01
    • 2013-12-14
    • 2017-11-19
    • 2014-07-06
    • 1970-01-01
    • 2010-09-17
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多