简体   繁体   English

在表格中打印 DescribeBy 的 output

[英]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.我想在一个漂亮的表格中打印我使用 describeBy function 获得的输出,以包含在我的报告中。

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?你知道有什么代码可以做到吗?

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)) 

You can use sjPlot package to have the descriptive statistics in word file like您可以使用sjPlot package 在 word 文件中进行描述性统计,例如

library(psych)
library(sjPlot)

tab_df(describe(iris),
       digits = 2,
  title = "Descriptive statistics", #give your tables title
  file = "Descriptive_statistics.doc")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM