drop_na drops entries by specified columns. delete_na deletes rows or columns with too many NAs.

drop_na(.data, ...)

delete_na(.data, MARGIN, n)

Arguments

.data

A data.table

...

Colunms to be dropped or deleted.

MARGIN

1 or 2. 1 for deleting rows, 2 for deleting columns.

n

If number (proportion) of NAs is larger than or equal to "n", the columns/rows would be deleted. When smaller than 1, use as proportion. When larger or equal to 1, use as number.

Value

A data.table

Examples

x = data.table(x = c(1, 2, NA, 3), y = c(NA, NA, 4, 5),z = rep(NA,4))
x
#>        x     y      z
#>    <num> <num> <lgcl>
#> 1:     1    NA     NA
#> 2:     2    NA     NA
#> 3:    NA     4     NA
#> 4:     3     5     NA
x %>% delete_na(2,0.75)
#>        x     y
#>    <num> <num>
#> 1:     1    NA
#> 2:     2    NA
#> 3:    NA     4
#> 4:     3     5

x = data.table(x = c(1, 2, NA, 3), y = c(NA, NA, 4, 5),z = rep(NA,4))
x %>% delete_na(2,0.5)
#>        x
#>    <num>
#> 1:     1
#> 2:     2
#> 3:    NA
#> 4:     3

x = data.table(x = c(1, 2, NA, 3), y = c(NA, NA, 4, 5),z = rep(NA,4))
x %>% delete_na(2,0.24)
#> Null data.table (0 rows and 0 cols)

x = data.table(x = c(1, 2, NA, 3), y = c(NA, NA, 4, 5),z = rep(NA,4))
x %>% delete_na(2,2)
#>        x
#>    <num>
#> 1:     1
#> 2:     2
#> 3:    NA
#> 4:     3

x = data.table(x = c(1, 2, NA, 3), y = c(NA, NA, 4, 5),z = rep(NA,4))
x %>% delete_na(1,0.6)
#>        x     y      z
#>    <num> <num> <lgcl>
#> 1:     3     5     NA
x = data.table(x = c(1, 2, NA, 3), y = c(NA, NA, 4, 5),z = rep(NA,4))
x %>% delete_na(1,2)
#>        x     y      z
#>    <num> <num> <lgcl>
#> 1:     3     5     NA