Skip to contents

Wrapper of tidyr::fill with checks for NAs in grouping values and the option to fill with the majority value if there is more than one value per group. If an error is raised, an example group that causes an error is returned

Usage

fillByGroup(
  df,
  group,
  fill,
  method = c("only_na", "all"),
  multiple = c("stop", "mode", "ignore")
)

Arguments

df

A data.frame or tibble with missing (NA) values to be filled

group

(character(n)) Names of column(s) to group by

fill

(character(n)) Name(s) of column(s) to fill

method

Either "only_na", of only missing entries should be filled, or "all", if all entries should be replaced with their group mode

multiple

(Default: "stop") How should multiple values in columns to be filled be handled? Either "stop" (raise an error), "mode" (select the most common value) or "ignore" (entries with multiple possible modes are set to NA).