Search code examples
rprintinghtml-tablepanel-data

Print the output of DescribeBy in a table


I would like to print the ouput I obtain with the describeBy function in a nice looking table to include in my report.

means<-describeBy(compdata1$lnfdinet, group=compdata1$namegeozone, mat=TRUE)
> means
    item group1 vars   n     mean       sd   median  trimmed      mad      min      max     range        skew    kurtosis         se
X11    1     AP    1 183 21.69083 1.996922 21.55382 21.61259 2.033396 16.41214 26.23397  9.821830  0.24999690 -0.05324277 0.14761670
X12    2    LAC    1 280 21.02388 1.900368 20.80716 20.98591 1.764128 15.86233 25.22215  9.359819  0.12315398 -0.21092124 0.11356872
X13    3  Other    1 239 21.55694 1.413843 21.50751 21.53762 1.586090 18.23622 24.98966  6.753438  0.09846572 -0.66249855 0.09145388
X14    4    SSA    1 327 19.79257 1.609993 20.00355 19.85755 1.491339 12.10486 23.52093 11.416070 -0.71694582  1.77092546 0.08903281

Do you know any code to do it?


Solution

  • I'm unsure of what software you are using to write your report, but the following may work for you.

    Note, when posting a question, please make your example reproducible by stating what packages you are using and using predefined datasets if possible.

      library(psych)
    
      means <- describeBy(mtcars$mpg, group=mtcars$gear, mat=TRUE)
    
      htmlTable::htmlTable(format(means, digits = 2))