report_nPct | R Documentation |
report_nPct builds a summary table with the frequency and percentage of the different values of one or more categorical variables. If a grouping variable is specified, absolute frequencies and percentages o values are computed in each group, and a chi-squared test is performed to test the association with the grouping variable. If conditions for the validity of the chi-squared test are not met, a Fisher exact test is performed instead.
report_nPct(
data,
summary_vars,
groupVar = NULL,
digits = 1,
pvdigits = 4,
na.rm = TRUE
)
data |
data frame or tibble which contains the variables. |
summary_vars |
Variables whose 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. |
na.rm |
Should missing values be included in the table? Percentages are always computed excluding missing values. |
A table with the overall frequencies and percentages of the values of the categorical variable and, if a grouping variable is specified, the frequencies and percentages of the values in each group as well as a chi-squared test for association between the variable and the grouping variable.
df <- data.frame(x=rbinom(90,3,0.6),y=rbinom(90,4,0.8), z=rbinom(90,5,0.5),
g=sample(c("Yes","No"),90,replace=TRUE))
df %>%
report_nPct(c(x,y,z)) # Overall summary of variables x, y and z
df %>%
report_nPct(c(x,y,z), groupVar=g, digits=3)
df$x[sample(1:90,15)]=NA # Some missing values are included in x
df$y[sample(1:90,8)]=NA # Some missing values are included in y
df %>% report_nPct(c(x,y,z), groupVar=g, digits=3, na.rm=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.