-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
75 lines (59 loc) · 2.48 KB
/
README.Rmd
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
title: "tidytable1"
author: "Liming Wang"
date: "8/15/2017"
output: html_document
---
Creates a Table1 for Descriptive Statistics with tidyverse utils
# Installation
```{r, echo=TRUE, eval=FALSE}
devtools::install_github("cities-lab/tidytable1")
```
# Usage
```{r, echo=TRUE, eval=TRUE}
library(tidytable1)
library(dplyr)
library(pander)
iris_tbl1 <- tidytable1(iris,
calc_cols=list(n=function(x) length(x)),
num_cols=c(min=min, median=median, max=max)) %>%
pp_table1(pp_vars=c("n"))
iris_tbl1 %>%
pander(missing="")
```
```{r, echo=TRUE, eval=TRUE, results="asis"}
library(htmlTable)
# tidytable1 differentiate numeric and non-numeric variables
mtcars_df <- mtcars %>%
mutate(cyl=factor(cyl), vs=factor(vs), am=factor(am, labels = c("automatic", "manual"))) %>%
as_tibble()
num_vars <- mtcars_df %>% select_if(is.numeric) %>% names
cat_vars <- mtcars_df %>% select_if(~!is.numeric(.)) %>% names
row_order <- list(Name=c(num_vars, cat_vars))
## organized variables by numeric + categorical
mtcars_tbl1 <- tidytable1(mtcars_df,
info_cols=list(Label=c(mpg="Miles/(US) gallon", cyl="Number of cylinders",
disp="Displacement (cu.in.)", hp="Gross horsepower",
drat="Rear axle ratio", wt="Weight (1000 lbs)",
qsec="1/4 mile time", vs="V/S",
am="Transmission", gear="Number of forward gears",
carb="Number of carburetors"),
Source=c(mpg="1974 Motor Trend")),
num_cols=c(mean=mean, sd=sd),
row_order = row_order) %>%
pp_table1(pp_vars=c("Label", "Source", "#missing"))
mtcars_tbl1 %>%
htmlTable(rnames = FALSE,
align="lll rrc rrr",
rgroup = c("Numeric Variables", "Categorical Variables"),
n.rgroup = c(length(num_vars), length(cat_vars)))
```
# TODO
- Enable stats by a grouping variable similar the behavior in `tableone`
- Add hypothesis testing functionality
# Related Projects
- [Gmisc](https://github.com/gforge/Gmisc)
- [tableone](https://github.com/kaz-yos/tableone)
- [stargazer](https://cran.r-project.org/web/packages/stargazer/)
# Build Status
[![Build Status](https://travis-ci.org/cities-lab/tidytable1.svg?branch=master)](travis-ci.org/cities-lab/tidytable1)