Skip to contents

Trim values

Usage

trim_values(
  df,
  col,
  value_col = "value",
  baseline_col = value_col,
  trim = TRUE,
  small_is_best = FALSE,
  keep_better_values = FALSE,
  upper_limit = 100,
  lower_limit = 0,
  trim_years = TRUE,
  start_year_trim = 2018,
  end_year_trim = 2025
)

Arguments

df

Data frame in long format, where 1 row corresponds to a specific country, year, and indicator.

col

column to trim values from. Will be removed before returning the data frame.

value_col

Column name of column with indicator values. This column will be used to return the results.

baseline_col

Column name with baseline values. This is used to ensure that trimmed values do not get worst values than baseline.

trim

logical to indicate if the data should be trimmed between upper_limit and lower_limit.

small_is_best

Logical to identify if a lower value is better than a higher one (e.g. lower obesity in a positive public health outcome, so obesity rate should have small_is_best = TRUE).

keep_better_values

logical to indicate if "better" values should be kept from value_col if they are present. Follows the direction set in small_is_best. For instance, if small_is_best is TRUE, then value_col lower than col will be kept.

upper_limit

upper limit at which the indicator should be caped.

lower_limit

lower_limit limit at which the indicator should be caped.

trim_years

logical to indicate if years before start_year_trim and after end_year_trim should be removed

start_year_trim

(integer) year to start trimming from.

end_year_trim

(integer) year to end trimming.

Value

trimed data frame, removing the col column, and putting the trimmed values in value_col