Learn R Programming

fastplyr (version 0.5.1)

f_fill: Fill NA values forwards and backwards

Description

Fill NA values forwards and backwards

Usage

f_fill(
  data,
  ...,
  .by = NULL,
  .cols = NULL,
  .direction = c("forwards", "backwards"),
  .fill_limit = Inf,
  .new_names = "{.col}"
)

Value

A data frame with NA values filled forward or backward.

Arguments

data

A data frame.

...

Cols to fill NA values specified through tidyselect notation. If left empty all cols are used by default.

.by

Cols to group by for this operation. Specified through tidyselect.

.cols

(Optional) alternative to ... that accepts a named character vector or numeric vector. If speed is an expensive resource, it is recommended to use this.

.direction

Which direction should NA values be filled? By default, "forwards" (Last-Observation-Carried-Forward) is used. "backwards" is (Next-Observation-Carried-Backward).

.fill_limit

The maximum number of consecutive NA values to fill. Default is Inf.

.new_names

A name specification for the names of filled variables. The default "{.col}" replaces the given variables with the imputed ones. New variables can be created alongside the originals if we give a different specification, e.g. .new_names = "{.col}_imputed". This follows the specification of dplyr::across if .fns were an empty string "".