Conditionally drop rows based on percent missingness
drop_row_if(df, sign = "gt", type = "count", value = 20, as_percent = TRUE)
A data.frame object
Character. One of gteq,lteq,lt,gt or eq which refer to greater than(gt) or equal(eq) or less than(lt) or equal to(eq) respectively.
One of either count or percent. Defaults to count
Value to use for the drop.
Logical. If set to TRUE, percent_na is treated as a percentage. Otherwise, decimals(fractions) are used.
head(drop_row_if(airquality,sign = "gteq",
type = "percent",value=16, as_percent = TRUE))
#> Dropped 42 rows.
#> Ozone Solar.R Wind Temp Month Day
#> 1 41 190 7.4 67 5 1
#> 2 36 118 8.0 72 5 2
#> 3 12 149 12.6 74 5 3
#> 4 18 313 11.5 62 5 4
#> 7 23 299 8.6 65 5 7
#> 8 19 99 13.8 59 5 8
# should give the same output as above.
head(drop_row_if(airquality, sign="gteq", type="percent",value = 0.15, as_percent=FALSE))
#> Dropped 42 rows.
#> Ozone Solar.R Wind Temp Month Day
#> 1 41 190 7.4 67 5 1
#> 2 36 118 8.0 72 5 2
#> 3 12 149 12.6 74 5 3
#> 4 18 313 11.5 62 5 4
#> 7 23 299 8.6 65 5 7
#> 8 19 99 13.8 59 5 8
# Drop based on NA counts
df <- data.frame(A=1:5, B=c(1,NA,NA,2, 3), C= c(1,NA,NA,2,3))
drop_row_if(df, type="count",value=2,sign="eq")
#> Dropped 2 rows.
#> A B C
#> 1 1 1 1
#> 4 4 2 2
#> 5 5 3 3