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.

112 lines
3.8KB

  1. % Generated by roxygen2: do not edit by hand
  2. % Please edit documentation in R/deprecated.R
  3. \name{desctable}
  4. \alias{desctable}
  5. \alias{desctable.default}
  6. \alias{desctable.grouped_df}
  7. \title{Generate a statistics table}
  8. \usage{
  9. desctable(data, stats, tests, labels)
  10. \method{desctable}{default}(data, stats = stats_auto, tests, labels = NULL)
  11. \method{desctable}{grouped_df}(data, stats = stats_auto, tests = tests_auto, labels = NULL)
  12. }
  13. \arguments{
  14. \item{data}{The dataframe to analyze}
  15. \item{stats}{A list of named statistics to apply to each element of the dataframe, or a function returning a list of named statistics}
  16. \item{tests}{A list of statistical tests to use when calling desctable with a grouped_df}
  17. \item{labels}{A named character vector of labels to use instead of variable names}
  18. }
  19. \value{
  20. A desctable object, which prints to a table of statistics for all variables
  21. }
  22. \description{
  23. Generate a statistics table with the chosen statistical functions, and tests if given a \code{"grouped"} dataframe.
  24. }
  25. \section{Labels}{
  26. labels is an option named character vector used to make the table prettier.
  27. If given, the variable names for which there is a label will be replaced by their corresponding label.
  28. Not all variables need to have a label, and labels for non-existing variables are ignored.
  29. labels must be given in the form c(unquoted_variable_name = "label")
  30. }
  31. \section{Stats}{
  32. The stats can be a function which takes a dataframe and returns a list of statistical functions to use.
  33. stats can also be a named list of statistical functions, or purrr::map like formulas.
  34. The names will be used as column names in the resulting table. If an element of the list is a function, it will be used as-is for the stats.
  35. }
  36. \section{Tests}{
  37. The tests can be a function which takes a variable and a grouping variable, and returns an appropriate statistical test to use in that case.
  38. tests can also be a named list of statistical test functions, associating the name of a variable in the data and a test to use specifically for that variable.
  39. That test name must be expressed as a single-term formula (e.g. \code{~t.test}), or a purrr::map like formula
  40. (e.g. \code{~t.test(., var.equal = T)}). You don't have to specify tests for all the variables: a default test for
  41. all other variables can be defined with the name \code{.default}, and an automatic test can be defined with the name \code{.auto}.
  42. If data is a grouped dataframe (using \code{group_by}), subtables are created and statistic tests are performed over each sub-group.
  43. }
  44. \section{Output}{
  45. The output is a desctable object, which is a list of named dataframes that can be further manipulated. Methods for printing, using in \pkg{pander} and \pkg{DT} are present. Printing reduces the object to a dataframe.
  46. }
  47. \examples{
  48. iris \%>\%
  49. desctable()
  50. # Does the same as stats_auto here
  51. iris \%>\%
  52. desctable(stats = list("N" = length,
  53. "Mean" = ~ if (is.normal(.)) mean(.),
  54. "sd" = ~ if (is.normal(.)) sd(.),
  55. "Med" = stats::median,
  56. "IQR" = ~ if(!is.factor(.)) IQR(.)))
  57. # With labels
  58. mtcars \%>\% desctable(labels = c(hp = "Horse Power",
  59. cyl = "Cylinders",
  60. mpg = "Miles per gallon"))
  61. # With grouping on a factor
  62. iris \%>\%
  63. group_by(Species) \%>\%
  64. desctable(stats = stats_default)
  65. # With nested grouping, on arbitrary variables
  66. mtcars \%>\%
  67. group_by(vs, cyl) \%>\%
  68. desctable()
  69. # With grouping on a condition, and choice of tests
  70. iris \%>\%
  71. group_by(Petal.Length > 5) \%>\%
  72. desctable(tests = list(.auto = tests_auto, Species = ~chisq.test))
  73. }
  74. \seealso{
  75. \code{\link{stats_auto}}
  76. \code{\link{tests_auto}}
  77. \code{\link{print.desctable}}
  78. \code{\link{pander.desctable}}
  79. \code{\link{datatable.desctable}}
  80. }
  81. \keyword{deprecated}