Package: dplyr


Function: filter()


  • Note: Using dplyr::across() in dplyr::filter() is deprecated. dplyr::if_any() and dplyr::if_all() are predicate functions used to select columns within dplyr::filter(). This function is available in version 1.0.5 of dplyr. dplyr::if_any() returns a true when the statement is true for any of the variables. dplyr::if_all() returns a true when the statement is true for all of the variables. See Filter using if_all or if_any for further explanation


1. Remove empty rows

Review the data (d9)

# A tibble: 6 x 5
  extra1 extra2 extra3    id test_score
  <chr>   <dbl>  <dbl> <dbl>      <dbl>
1 a           1      2    10        205
2 b        -999      0    11        220
3 c           3   -999    12        250
4 d          NA      0    13        217
5 <NA>       NA     NA    NA         NA
6 e          NA     NA    NA         NA

Filter out any completely empty row

  • Note: Note the use of tidyselect::everything() to select all variables
d9 %>% 
  dplyr::filter(!dplyr::if_all(tidyselect::everything(), ~ is.na(.)))
# A tibble: 5 x 5
  extra1 extra2 extra3    id test_score
  <chr>   <dbl>  <dbl> <dbl>      <dbl>
1 a           1      2    10        205
2 b        -999      0    11        220
3 c           3   -999    12        250
4 d          NA      0    13        217
5 e          NA     NA    NA         NA

Package: expss


Function: drop_empty_rows()


1. Filter out empty rows

Review the data (d1)

# A tibble: 5 x 5
  extra1 extra2 extra3    id test_score
  <chr>   <dbl>  <dbl> <dbl>      <dbl>
1 a           1      2    10        205
2 b        -999      0    11        220
3 c           3   -999    12        250
4 d           4      0    13        217
5 <NA>       NA     NA    NA         NA

Filter out any completely empty row

d1 %>% 
  expss::drop_empty_rows()
# A tibble: 4 x 5
  extra1 extra2 extra3    id test_score
  <chr>   <dbl>  <dbl> <dbl>      <dbl>
1 a           1      2    10        205
2 b        -999      0    11        220
3 c           3   -999    12        250
4 d           4      0    13        217

Package: janitor


Function: remove_empty()


1. Remove empty rows

Review the data (d1)

# A tibble: 5 x 5
  extra1 extra2 extra3    id test_score
  <chr>   <dbl>  <dbl> <dbl>      <dbl>
1 a           1      2    10        205
2 b        -999      0    11        220
3 c           3   -999    12        250
4 d           4      0    13        217
5 <NA>       NA     NA    NA         NA

Filter out any completely empty row

d1 %>% 
  janitor::remove_empty("rows")
# A tibble: 4 x 5
  extra1 extra2 extra3    id test_score
  <chr>   <dbl>  <dbl> <dbl>      <dbl>
1 a           1      2    10        205
2 b        -999      0    11        220
3 c           3   -999    12        250
4 d           4      0    13        217

Return to Filter