Skip to content

05_drop_NA_cols

mike edited this page May 4, 2018 · 1 revision

Maritimes/Mar.utils - Removing Useless Fields

May 2, 2018 - Mike McMahon (mike.mcmahon@dfo-mpo.gc.ca)

drop_NA_cols.R

This function takes a dataframe and removes any columns that are entirely populated with NAs

> head(data)
     MISSION SETNO LATITUDE LONGITUDE TOTNO GARBAGE
1 ATC1970176    10 91.00000 -60.88333  1642      NA
2 ATC1970176    13 44.81667        NA  1107      NA
3 ATC1970176    15 44.16667 -59.85000    41      NA
4 ATC1970176    17 44.33333 -60.51667   560      NA
5 ATC1970176     1 44.31667 -62.20000   947      NA
6 ATC1970176    23 43.41667 -60.56667     7      NA

>data_clean = drop_NA_cols(data)
> head(data_clean)
     MISSION SETNO LATITUDE LONGITUDE TOTNO
1 ATC1970176    10 91.00000 -60.88333  1642
2 ATC1970176    13 44.81667        NA  1107
3 ATC1970176    15 44.16667 -59.85000    41
4 ATC1970176    17 44.33333 -60.51667   560
5 ATC1970176     1 44.31667 -62.20000   947
6 ATC1970176    23 43.41667 -60.56667     7

Clone this wiki locally