Search code examples
rr-markdownxtable

R describe and R Markdown


I'd like to describe my data table in a R Markdown file using

xtable(data, type='html')

But none of the packages I looked so far seem to be compatible with xtable in html setting, f.i. Hmisc::describe,reporttools::tableNominal.

Does anyone have a solution for this?

Example: Something like Variables Overview with xtable in R but working in Markdown/html.


Solution

  • Ok, I've found one option that does work well with R markdown and that is using the psych::describe command. This has the advantage that the final table is a data.frame object that can then be further manipulated.

    with xtable

    library(psych)
    library(xtable)
    table.desc <- describe(mytable)
    print(xtable(table.desc), type="html")
    

    or using Gmisc

    library(psych)
    table.desc <- describe(mytable)
    table.prep <- as.matrix(table.desc)
    library(Gmisc)
    htmlTable(table.prep)
    

    Please note that in this example you do want to include the rownames, as they are part of the describe output. Also Gmisc inherits the Hmisc::describe command and has thus to be loaded AFTER creating the stats table.