table_one | R Documentation |
table_one
table_one(df, group, datadic = NULL, var_name, var_desp)
df |
Dataframe consisting of numeric, logical, and factor variables with or without a grouping variable |
group |
Name of the grouping variable. |
Main function that users interact. table_one
calculate the selected summary statistics for continuous, logical,
and factor variables per statitstical guidelines of the Annals of medicine. If a group variable is provided, then
it will also assess the between-group difference.The input data frame should only consists of numeric, logical
and factor variables. Factor variables with
only two levels should be converted to logical variables. Date and datetime variables should be removed.
The function returns a dataframe, rows of which are summary statistics depending on the variable types.
set.seed(0)
df<- data_frame(sex = factor(c(rep("F", 90), rep("M", 900))),
grade = factor(sample(c("A", "B", "C"), 990, replace= TRUE), c("A", "B", "C", "D")),
income= 100 * (rnorm(990) + 5),
dm= rbernoulli(990, p= .5),
af= rbernoulli(990, p= .95)) %>%
mutate(weight= if_else( sex=="F" & income>500, 3, 1),
income= ifelse(income<456, NA, income),
sex = ifelse(runif(990)<.2, NA, sex),
sex = factor(sex, 1:2, labels = c("Female", "Male")),
grade = ifelse(runif(990)<.25, NA, grade),
grade = factor(grade, 1:4, labels = c("A", "B", "C", "D")))
datadic<- data.frame(var_name= c("sex", "grade", "income", "dm", "af"),
var_desp= c("Sex", "Grade", "Household income",
"Presence of diabetes mellitus", "African American"),
stringsAsFactors = FALSE)
table_one(df, sex)
table_one(df, sex, datadic= datadic)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.