Learn R Programming

tidyfst (version 0.7.7)

drop_na_dt: Dump, replace and fill missing values in data.frame

Description

Analogous function for drop_na, replace_na and fill in tidyr, but with a different API.

Usage

drop_na_dt(data, ...)

replace_na_dt(data, ..., to)

fill_na_dt(data, ..., direction = c("down", "up"))

Arguments

data

data.frame

...

Colunms to be replaced or filled. If not specified, use all columns.

to

What value should NA replace by?

direction

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

Value

data.table

References

https://stackoverflow.com/questions/7235657/fastest-way-to-replace-nas-in-a-large-data-table

See Also

drop_na,replace_na, fill

Examples

Run this code
# NOT RUN {
df <- data.table(x = c(1, 2, NA), y = c("a", NA, "b"))
 df %>% drop_na_dt()
 df %>% drop_na_dt(x)
 df %>% drop_na_dt(y)
 df %>% drop_na_dt(x,y)

 df %>% replace_na_dt(to = 0)
 df %>% replace_na_dt(x,to = 0)
 df %>% replace_na_dt(y,to = 0)
 df %>% replace_na_dt(x,y,to = 0)

 df %>% fill_na_dt(x)
 df %>% fill_na_dt() # not specified, fill all columns
 df %>% fill_na_dt(y,direction = "up")
# }

Run the code above in your browser using DataLab