Skip to contents

Counts rows per group (or overall), optionally the number of distinct values of a column and the rows per distinct value, the share of all counted rows, and counts of selected values of further columns.

Usage

PlotDataCount(
  data,
  by = NULL,
  filter = NULL,
  distinct = NULL,
  tally = NULL,
  scale = 100
)

Arguments

data

A data frame.

by

Grouping columns (none for one overall row).

filter

Optional named list of columns and values selecting rows.

distinct

Optional column whose distinct values are counted.

tally

Optional named list of extra counts: each a list of column and values.

scale

Multiplier of the share (100 for percentages).

Value

A data frame with the groups, n, share, and if requested n_distinct, n_per_distinct (integer division) and the tallies.

Examples

d <- data.frame(g = c("a", "a", "b"), p = c("x", "y", "x"), t = c("T", "U", "T"))
PlotDataCount(d, "g", distinct = "p", tally = list(n_t = list(column = "t", values = "T")))
#>   g n    share n_distinct n_per_distinct n_t
#> 1 a 2 66.66667          2              1   1
#> 2 b 1 33.33333          1              1   1