addon-dplyr: Functions to summarise count with percentage within a...

Description Usage Value Examples

Description

count_pct is the extenstion of dplyr::count with percent count_pct_group is the extenstion of dplyr::count with percent by group

Usage

1
2
3
count_pct(.data, ..., sort = FALSE, accuracy = 3)

count_pct_group(.data, ..., accuracy = 3)

Value

returns a dataframe with count and percentage columns

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(dacol, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
library(scales, warn.conflicts = FALSE)

df = data.frame(x = c(1, 2, 3, 4, 5),
                y = c("b", "a", "k", "b", "k"),
                z = c(5, 8, 8, 6, 5))

df %>% count_pct(y)
df %>% count_pct(z)

mtcars %>% count_pct(cyl)
mtcars %>% count_pct(cyl, sort = TRUE)
mtcars %>% count_pct(cyl, am, sort = TRUE)

mtcars %>% count_pct_group(cyl)
mtcars %>% count_pct_group(cyl, am)
mtcars %>% count_pct_group(cyl, am) %>% arrange(cyl, desc(n))

ldanai/dacol documentation built on May 15, 2020, 5:05 p.m.