You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.md 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. Desctable
  2. ================
  3. [![Travis-CI Build
  4. Status](https://travis-ci.org/desctable/desctable.svg?branch=master)](https://travis-ci.org/desctable/desctable)
  5. [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/desctable)](https://cran.r-project.org/package=desctable)
  6. [![CRAN RStudio mirror
  7. downloads](http://cranlogs.r-pkg.org/badges/desctable)](https://www.r-pkg.org:443/pkg/desctable)
  8. [![CRAN RStudio mirror total
  9. downloads](http://cranlogs.r-pkg.org/badges/grand-total/desctable)](https://www.r-pkg.org:443/pkg/desctable)
  10. **Warning to existing users**
  11. *This version introduces a new API that should make the creation of
  12. tables more flexible.
  13. The old API is still present but in a deprecated mode.
  14. See the roadmap below, and the website for the new usage.
  15. Suggestions about this change are welcome !*
  16. ------------------------------------------------------------------------
  17. # Introduction
  18. Desctable aims to be a simple and expressive interface to building
  19. statistical tables in R.
  20. # Installation
  21. Install from CRAN with
  22. install.packages("desctable")
  23. or install the development version from github with
  24. devtools::install_github("desctable/desctable")
  25. # Basic usage
  26. Load the package
  27. ``` r
  28. library(desctable)
  29. ```
  30. Simply apply `desc_table` on a dataframe or a grouped dataframe to get a
  31. statistical table
  32. ``` r
  33. iris %>%
  34. desc_table()
  35. ```
  36. ## Variables N % Min Q1 Med Mean Q3 Max
  37. ## 1 Sepal.Length 150 NA 4.3 5.1 5.80 5.843333 6.4 7.9
  38. ## 2 Sepal.Width 150 NA 2.0 2.8 3.00 3.057333 3.3 4.4
  39. ## 3 Petal.Length 150 NA 1.0 1.6 4.35 3.758000 5.1 6.9
  40. ## 4 Petal.Width 150 NA 0.1 0.3 1.30 1.199333 1.8 2.5
  41. ## 5 **Species** 150 NA NA NA NA NA NA NA
  42. ## 6 **Species**: *setosa* 50 33.33333 NA NA NA NA NA NA
  43. ## 7 **Species**: *versicolor* 50 33.33333 NA NA NA NA NA NA
  44. ## 8 **Species**: *virginica* 50 33.33333 NA NA NA NA NA NA
  45. ## sd IQR
  46. ## 1 0.8280661 1.3
  47. ## 2 0.4358663 0.5
  48. ## 3 1.7652982 3.5
  49. ## 4 0.7622377 1.5
  50. ## 5 NA NA
  51. ## 6 NA NA
  52. ## 7 NA NA
  53. ## 8 NA NA
  54. Declare the statistics you want to see, and give them the name of your
  55. choice
  56. ``` r
  57. iris %>%
  58. desc_table("N" = length,
  59. "%" = percent,
  60. mean,
  61. sd)
  62. ```
  63. ## Variables N % mean sd
  64. ## 1 Sepal.Length 150 NA 5.843333 0.8280661
  65. ## 2 Sepal.Width 150 NA 3.057333 0.4358663
  66. ## 3 Petal.Length 150 NA 3.758000 1.7652982
  67. ## 4 Petal.Width 150 NA 1.199333 0.7622377
  68. ## 5 **Species** 150 NA NA NA
  69. ## 6 **Species**: *setosa* 50 33.33333 NA NA
  70. ## 7 **Species**: *versicolor* 50 33.33333 NA NA
  71. ## 8 **Species**: *virginica* 50 33.33333 NA NA
  72. Create comparative tables, compute statistical tests and output to
  73. `pander` for crisp markdown rendering!
  74. ``` r
  75. mtcars %>%
  76. dplyr::mutate(cyl = factor(cyl),
  77. vs = factor(vs, labels = c("V-shaped", "straight")),
  78. am = factor(am, labels = c("automatic", "manual"))) %>%
  79. group_by(am) %>%
  80. desc_table(N = length,
  81. "%" = percent,
  82. "Median" = median,
  83. IQR) %>%
  84. desc_tests(vs = ~chisq.test) %>%
  85. desc_output("pander")
  86. ```
  87. |   | am = manual</br> (N = 13)</br> N | % | Median | IQR | am = automatic</br> (N = 19)</br> N | % | Median | IQR | p | test |
  88. |:-------------|:---------------------------------|:----|:-------|:-----|:------------------------------------|:----|:-------|:-----|:--------|:------------|
  89. | mpg | 13 | | 23 | 9.4 | 19 | | 17 | 4.2 | \< 0.01 | wilcox.test |
  90. | **cyl** | 13 | | | | 19 | | | | \< 0.01 | fisher.test |
  91. |     4 | 8 | 62 | | | 3 | 16 | | | | |
  92. |     6 | 3 | 23 | | | 4 | 21 | | | | |
  93. |     8 | 2 | 15 | | | 12 | 63 | | | | |
  94. | disp | 13 | | 120 | 81 | 19 | | 276 | 164 | \< 0.01 | wilcox.test |
  95. | hp | 13 | | 109 | 47 | 19 | | 175 | 76 | 0.046 | wilcox.test |
  96. | drat | 13 | | 4.1 | 0.37 | 19 | | 3.1 | 0.63 | \< 0.01 | wilcox.test |
  97. | wt | 13 | | 2.3 | 0.84 | 19 | | 3.5 | 0.41 | \< 0.01 | wilcox.test |
  98. | qsec | 13 | | 17 | 2.1 | 19 | | 18 | 2 | 0.27 | wilcox.test |
  99. | **vs** | 13 | | | | 19 | | | | 0.56 | chisq.test |
  100. |     V-shaped | 6 | 46 | | | 12 | 63 | | | | |
  101. |     straight | 7 | 54 | | | 7 | 37 | | | | |
  102. | gear | 13 | | 4 | 1 | 19 | | 3 | 0 | \< 0.01 | wilcox.test |
  103. | carb | 13 | | 2 | 3 | 19 | | 3 | 2 | 0.74 | wilcox.test |
  104. Read more in the [vignette](articles/desctable.html) !