kpi_fn_: KPI summary functions

kpi_fn_nR Documentation

KPI summary functions

Description

These functions are not intended to be run as they are. They are intended to be passed as arguments to the kpi or kpi_calc functions. They summarize the data in the appropriate manner for the type of KPI. For example, the kpi_fn_prop counts the number of cases and total number of observations then calculates a proportion. kpi_fn_median simply calculates the median of the observations.

Usage

kpi_fn_n(.data)

kpi_fn_prop(.data)

kpi_fn_perc(.data)

kpi_fn_median(.data)

kpi_fn_mean(.data)

kpi_fn_iqr(.data)

kpi_fn_min(.data)

kpi_fn_max(.data)

kpi_fn_missing(.data)

Arguments

.data

data frame

Details

Functions should accept a dataframe with a var variable and return a dataframe with stat (other variables are optional, although an N variable allows for compatibility with downstream functions). All provided functions return stat, n_nonmiss and N, with some also returning n.

See the examples passing custom functions.

Examples

# mean
kpi(mtcars, "mpg", kpi_fn = kpi_fn_mean)
# median
kpi(mtcars, "mpg", kpi_fn = kpi_fn_median)
# interquartile range
kpi(mtcars, "mpg", kpi_fn = kpi_fn_iqr)
# minimum
kpi(mtcars, "mpg", kpi_fn = kpi_fn_min)
# maximum
kpi(mtcars, "mpg", kpi_fn = kpi_fn_max)
# proportion
kpi(mtcars, "am", kpi_fn = kpi_fn_prop)
# percentage
kpi(mtcars, "am", kpi_fn = kpi_fn_perc)
# number/sum
kpi(mtcars, "am", kpi_fn = kpi_fn_n)





CTU-Bern/kpitools documentation built on Aug. 19, 2024, 4:58 a.m.