report_nPctBin01 | R Documentation |
report_nPctBin01 builds a summary table with the frequency and percentage of times that one or more binary 0-1 variables takes the value 1. If a grouping variable is specified, absolute frequencies and percentages of 1's are computed in each group, and a chi-squared test is performed to test the difference of proportions of 1's between groups. If conditions for the validity of the chi-squared test are not met, a Fisher exact test is performed instead.
report_nPctBin01(data, summary_vars, groupVar = NULL, digits = 1, pvdigits = 4)
data |
data frame or tibble which contains the variables. |
summary_vars |
Binary variables which frequencies and percentages are to be computed |
groupVar |
Grouping variables. |
digits |
Number of decimal digits of the result. |
pvdigits |
Number of decimal digits in the p-value of chi-squared test. |
A table with the overall frequencies and percentages of 1's in each one of the required variables and, if a grouping variable is specified, the frequencies and percentages of 1's in each group as well as a chi-squared test for comparing proportions of 1's between groups.
df <- data.frame(x=rbinom(90,1,0.3),y=rbinom(90,1,0.8), z=rbinom(90,1,0.5),
g=sample(c("Yes","No"),90,replace=TRUE))
df %>%
report_nPctBin01(c(x,y,z)) # Overall summary of variables x, y and z
df %>%
report_nPctBin01(c(x,y,z), groupVar=g, digits=3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.