Skip to contents

This function can be used to perform a number of mathematical operation on a dataframe. Count or sum numerical values by group, get percent breakdown of counts or sums by group, and get optional zscore of values.

Usage

count_percent_zscore(
  data,
  grp_c = ...,
  grp_p = ...,
  grp_z = ...,
  col,
  prefix = NULL,
  rnd = NULL,
  cntr_scl = FALSE
)

Arguments

data

a dataframe

grp_c

a vector of columns to group counting operation with - do not quote columns

grp_p

a vector of columns to group percent calculation operation with - do not quote columns

grp_z

a vector of columns to group zscore calculation operation with - do not quote columns

col

a column to count or sum - do not quote column

prefix

a string used to prefix calculated columns with - leave empty if you do not want a prefix

rnd

integer indicating how many digits you want calculated columns to be rounded to - leave empty if you do not want rounding

cntr_scl

(`TRUE`/`FALSE`) boolean to indicate if zscore should be calculated - default is `FALSE`

Value

a dataframe

Examples


if (FALSE) { # \dontrun{
temp_data = data.frame(group = c(rep("A", 4), rep("B", 4))
                      ,order = c(1:4, 1:4)) %>%
 mutate(value = 2*order+rnorm(8, 5)
        ,count = 1)

count_percent_zscore(temp_data, grp_c = c(group), grp_p = c(), col = count)

count_percent_zscore(temp_data, grp_c = c(order), grp_p = c(), col = value)
} # }