Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fill

Fill in missing values with previous or next value


Description

Fills missing values in selected columns using the next or previous entry.

Usage

fill(.data, ..., direction = "down")

shift_fill(x, direction = "down")

Arguments

.data

A data.table

...

A selection of columns.

direction

Direction in which to fill missing values. Currently either "down" (the default), "up".

x

A vector.

Details

fill is filling data.table's columns, shift_fill is filling any vectors.

Value

A filled data.table

Examples

df <- data.table(Month = 1:12, Year = c(2000, rep(NA, 10),2001))
df
df %>% fill(Year)

df <- data.table(Month = 1:12, Year = c(2000, rep(NA, 10),2001))
df %>% fill(Year,direction = "up")

tidyft

Tidy Verbs for Fast Data Operations by Reference

v0.4.5
MIT + file LICENSE
Authors
Tian-Yuan Huang [aut, cre] (<https://orcid.org/0000-0002-3591-4203>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.