Learn R Programming

tidyft (version 0.9.20)

drop_na: Drop or delete data by rows or columns

Description

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

Usage

drop_na(.data, ...)

delete_na(.data, MARGIN, n)

Value

A data.table

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.

Examples

Run this code
x = data.table(x = c(1, 2, NA, 3), y = c(NA, NA, 4, 5),z = rep(NA,4))
x
x %>% delete_na(2,0.75)

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 = data.table(x = c(1, 2, NA, 3), y = c(NA, NA, 4, 5),z = rep(NA,4))
x %>% delete_na(2,0.24)

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 = 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 = data.table(x = c(1, 2, NA, 3), y = c(NA, NA, 4, 5),z = rep(NA,4))
x %>% delete_na(1,2)


Run the code above in your browser using DataLab