groupwiseCount: Groupwise count

View source: R/dbplyHelper.R

groupwiseCountR Documentation

Groupwise count

Description

Performs a 2 level count either preserving the structure of the dataframe (e.g. as a mutate function) or as a summary, returning the dataframe with total counts for the grouping (N) and for the subgroup defined by "groupVars" (N_x). This also allows us to calculate a probability of the subgroup in the group. This is different from an rank_percent in that the input datafram may have already been summarised

Usage

groupwiseCount(df, groupVars, countVar = NULL, summarise = FALSE)

Arguments

df

- a df which may be grouped. Grouping typically will be on a feature. N is the count of the items in the group

groupVars

- the grouping for which we want to create a label as a list of columns quoted by vars(...). This could be an outcome and

countVar

- optional: the datatable column containing the observed frequency of the event X. If this is missing the row count will be used instead (i.e. assumes each row is an observation).

summarise

- return dataframe as-is with additional columns (N, N_x, p_x) (FALSE - the default) or return dataframe as group summary with only grouping info and output (TRUE)

Value

the grouped dataframe containing at a minumum, the df grouping columns, the groupVars columns, and a groupwise count of both levels of grouping labelled N and N_x and the groupwise p_x.

Examples

mtcars %>% group_by(cyl) %>% groupwiseCount(vars(gear), summarise=TRUE) %>% mutate(p_x = N_x/N)

terminological/tidy-info-stats documentation built on Nov. 19, 2022, 11:23 p.m.