Produces a descriptive table, stratified by an optional categorical variable, providing means/frequencies and standard deviations/percentages. It is well-formatted for easy transition to academic article or report. Can be used within the piping framework [see library(magrittr)].

1 2 3 4 5 6 7 | ```
table1(.data, ..., all = FALSE, splitby = NULL, row_wise = FALSE,
splitby_labels = NULL, medians = NULL, test = FALSE,
test_type = "default", simple = FALSE, condense = FALSE,
piping = FALSE, rounding = 2, rounding_perc = 1, var_names = NULL,
format_output = "pvalues", output_type = "text", format_number = FALSE,
NAkeep = FALSE, m_label = "Missing", booktabs = TRUE, caption = NULL,
align = NULL, export = NULL)
``` |

`.data` |
the data.frame that is to be summarized |

`...` |
variables in the data set that are to be summarized; unquoted names separated by commas (e.g. age, gender, race) or indices. If indices, it needs to be a single vector (e.g. c(1:5, 8, 9:20) instead of 1:5, 8, 9:20). As it is currently, it CANNOT handle both indices and unquoted names simultaneously. |

`all` |
logical; if set to |

`splitby` |
the categorical variable to stratify by in formula form (e.g., |

`row_wise` |
how to calculate percentages for factor variables when |

`splitby_labels` |
allows for custom labels of the splitby levels; must match the number of levels of the splitby variable |

`medians` |
a vector or list of continuous variables for which medians and 25% and 75% quartiles should be produced |

`test` |
logical; if set to |

`test_type` |
has two options: "default" performs the default tests of significance only; "or" also give unadjusted odds ratios as well based on logistic regression (only use if splitby has 2 levels) |

`simple` |
logical; if set to |

`condense` |
logical; if set to |

`piping` |
if |

`rounding` |
the number of digits after the decimal for means and SD's; default is 2 |

`rounding_perc` |
the number of digits after the decimal for percentages; default is 1 |

`var_names` |
custom variable names to be printed in the table |

`format_output` |
has three options (with partial matching): 1) "full" provides the table with the type of test, test statistic, and the p-value for each variable; 2) "pvalues" provides the table with the p-values; and 3) "stars" provides the table with stars indicating significance. Only "p-values" works when |

`output_type` |
default is "text"; the other options are all format options in the |

`format_number` |
default in FALSE; if TRUE, then the numbers are formatted with commas (e.g., 20,000 instead of 20000) |

`NAkeep` |
when sset to |

`m_label` |
when |

`booktabs` |
when |

`caption` |
when |

`align` |
when |

`export` |
character; when given, it exports the table to a CSV file to folder named "table1" in the working directory with the name of the given string (e.g., "myfile" will save to "myfile.csv") |

A table with the number of observations, means/frequencies and standard deviations/percentages is returned. The object is a `table1`

class object with a print method. Can be printed in `LaTex`

form.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ```
## Ficticious Data ##
library(furniture)
library(tidyverse)
x <- runif(1000)
y <- rnorm(1000)
z <- factor(sample(c(0,1), 1000, replace=TRUE))
a <- factor(sample(c(1,2), 1000, replace=TRUE))
df <- data.frame(x, y, z, a)
## Simple
table1(df, x, y, z, a)
## Stratified
## both below are the same
table1(df, x, y, z,
splitby = ~ a)
table1(df, x, y, z,
splitby = "a")
## With Piping
df %>%
table1(x, y, z,
splitby = ~a,
piping = TRUE) %>%
summarise(count = n())
## Adjust variables within function
table1(df, ifelse(x > 0, 1, 0), z,
var_names = c("X2", "Z"))
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.