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.

99 lines
3.0KB

  1. % Generated by roxygen2: do not edit by hand
  2. % Please edit documentation in R/build.R
  3. \name{desc_table}
  4. \alias{desc_table}
  5. \alias{desc_table.default}
  6. \alias{desc_table.data.frame}
  7. \alias{desc_table.grouped_df}
  8. \title{Generate a statistics table}
  9. \usage{
  10. desc_table(data, ..., .auto, .labels)
  11. \method{desc_table}{default}(data, ..., .auto, .labels)
  12. \method{desc_table}{data.frame}(data, ..., .labels = NULL, .auto = stats_auto)
  13. \method{desc_table}{grouped_df}(data, ..., .auto = stats_auto, .labels = NULL)
  14. }
  15. \arguments{
  16. \item{data}{The dataframe to analyze}
  17. \item{...}{A list of named statistics to apply to each element of the dataframe, or a function returning a list of named statistics}
  18. \item{.auto}{A function to automatically determine appropriate statistics}
  19. \item{.labels}{A named character vector of variable labels}
  20. }
  21. \value{
  22. A simple or grouped descriptive table
  23. }
  24. \description{
  25. Generate a statistics table with the chosen statistical functions, nested if called with a grouped dataframe.
  26. }
  27. \section{Stats}{
  28. The statistical functions to use in the table are passed as additional arguments.
  29. If the argument is named (eg. \code{N = length}) the name will be used as the column title instead of the function
  30. name (here, \strong{N} instead of \strong{length}).
  31. Any R function can be a statistical function, as long as it returns only one value when applied to a vector, or as
  32. many values as there are levels in a factor, plus one.
  33. Users can also use \code{purrr::map}-like formulas as quick anonymous functions (eg. \code{Q1 = ~ quantile(., .25)} to get the first quantile in a
  34. column named \strong{Q1})
  35. If no statistical function is given to \code{desc_table}, the \code{.auto} argument is used to provide a function
  36. that automatically determines the most appropriate statistical functions to use based on the contents of the table.
  37. }
  38. \section{Labels}{
  39. \code{.labels} is a named character vector to provide "pretty" labels to variables.
  40. If given, the variable names for which there is a label will be replaced by their corresponding label.
  41. Not all variables need to have a label, and labels for non-existing variables are ignored.
  42. labels must be given in the form \code{c(unquoted_variable_name = "label")}
  43. }
  44. \section{Output}{
  45. The output is either a dataframe in the case of a simple descriptive table,
  46. or nested dataframes in the case of a comparative table.
  47. }
  48. \examples{
  49. iris \%>\%
  50. desc_table()
  51. # Does the same as stats_auto here
  52. iris \%>\%
  53. desc_table("N" = length,
  54. "Min" = min,
  55. "Q1" = ~quantile(., .25),
  56. "Med" = median,
  57. "Mean" = mean,
  58. "Q3" = ~quantile(., .75),
  59. "Max" = max,
  60. "sd" = sd,
  61. "IQR" = IQR)
  62. # With grouping on a factor
  63. iris \%>\%
  64. group_by(Species) \%>\%
  65. desc_table(.auto = stats_auto)
  66. }
  67. \seealso{
  68. \code{\link{stats_auto}}
  69. \code{\link{IQR}}
  70. \code{\link{percent}}
  71. Other desc_table core functions:
  72. \code{\link{desc_output}()},
  73. \code{\link{desc_tests}()}
  74. }
  75. \concept{desc_table core functions}