pcount: Wrapper for 'count()' with percentages

View source: R/pcount.R

pcountR Documentation

Wrapper for count() with percentages

Description

Shortcut for count(x) |> mutate(p = n/sum(n)). Returns APA compliant percentage values from table data.

Usage

pcount(tbl, x, rounded = TRUE, name = "n", ...)

Arguments

tbl

Table

x

The variable to count and calculate the percentage on.

rounded

logical. Return rounded percentage. If false decimal values will be used.

name

character. The name of the new column in the output. If omitted, it will default to n.

...

Other arguments passed to count.

Value

pcount() returns the same as count() with an aditional percentage column. See count.

Examples

## Not run: 
dat <- tibble(group = rep(1:5, each = 2),
              letter = c("a", "b",
                         "a", "c",
                         "a", "c",
                         "b", "e",
                         "b", "f"))

pcount(dat, letter)
pcount(dat, letter, sort = TRUE)
pcount(dat, letter, name = "obs")

## End(Not run)


Kudusch/ktools documentation built on Oct. 30, 2022, 10:13 p.m.