kpi_fn_n | R Documentation |
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.
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)
.data |
data frame |
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.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.