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

drop_na_dt(data, ...)

replace_na_dt(data, ..., to)

Arguments

data

data.frame

...

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

to

What value should NA replace by?

Value

data.table

References

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

See also

Examples

df <- data.table(x = c(1, 2, NA), y = c("a", NA, "b")) df %>% drop_na_dt()
#> x y #> 1: 1 a
df %>% drop_na_dt(x)
#> x y #> 1: 1 a #> 2: 2 <NA>
df %>% replace_na_dt(to = 0)
#> x y #> 1: 1 a #> 2: 2 0 #> 3: 0 b
df %>% replace_na_dt(x,to = 0)
#> x y #> 1: 1 a #> 2: 2 <NA> #> 3: 0 b
df %>% replace_na_dt(y,to = 0)
#> x y #> 1: 1 a #> 2: 2 0 #> 3: NA b