Analogous function for drop_na
and replace_na
in tidyr, but with a different API.
drop_na_dt(data, ...) replace_na_dt(data, ..., to)
data | data.frame |
---|---|
... | Colunms to be replaced. If not specified, use all columns. |
to | What value should NA replace by? |
data.table
https://stackoverflow.com/questions/7235657/fastest-way-to-replace-nas-in-a-large-data-table
#> x y #> 1: 1 adf %>% 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 bdf %>% replace_na_dt(x,to = 0)#> x y #> 1: 1 a #> 2: 2 <NA> #> 3: 0 bdf %>% replace_na_dt(y,to = 0)#> x y #> 1: 1 a #> 2: 2 0 #> 3: NA b