Summarises frequencies and percentages for a categorical variable.
The function accepts an input from a dplyr pipe "%>%" and outputs the results as a tibble. eg. example_data %>% tab1(variable)
Examples
example_data <- dplyr::tibble(id = 1:100, group = sample(c("a", "b", "c", "d"),
size = 100, replace = TRUE))
example_data$group[sample(1:100, size = 10)] <- NA # Replace 10 with missing
tab1(example_data, group)
#> # A tibble: 6 × 3
#> Category Frequency Percent
#> <chr> <int> <chr>
#> 1 a 26 26.0
#> 2 c 26 26.0
#> 3 b 20 20.0
#> 4 d 18 18.0
#> 5 NA 10 10.0
#> 6 Total 100 100.0
summary <- tab1(example_data, group) # Save summary statistics as a tibble.
#> # A tibble: 6 × 3
#> Category Frequency Percent
#> <chr> <int> <chr>
#> 1 a 26 26.0
#> 2 c 26 26.0
#> 3 b 20 20.0
#> 4 d 18 18.0
#> 5 NA 10 10.0
#> 6 Total 100 100.0