I have a df that I would like to remove rows in which columns 2:nrow(df) ALL contain NA. This df is one example containing water quality parameters. however in my code the size of the df will vary depending on how many parameters are available per query. some may have 4 like the df below, some may have 6.
DATE_TIME WT SC DO SAL
1 2017-05-31 11:00:00 NA NA NA NA
2 2017-05-31 11:15:00 NA NA NA NA
3 2017-05-31 11:30:00 NA NA NA NA
4 2017-06-13 12:45:00 NA 30 19 5.4
5 2017-07-05 11:45:00 NA NA NA 4.9
I would like the output to look like:
DATE_TIME WT SC DO SAL
1 2017-06-13 12:45:00 NA 30 19 5.4
2 2017-07-05 11:45:00 NA NA NA 4.9
I have tried to use something like:
colnum <- ncol(df) #count col because my df size will be variable
df <-df[complete.cases(df[ , 2:colnum]),]
but that just leaves me with:
DATE_TIME WT SC DO SAL
1 2017-06-13 12:45:00 NA 30 19 5.4
anything quick and dirty would be appreciated! Cheers! and double cheers for not giving me a -1 ;)
Also I see there are a few similar questions out there, but i dont think they are entirely the same as this. the answer can't remove the row if all columns contain NA, since the date column will never be an NA. it specifically has to remove the rows if each column, col2:ncol(df), contain NA. hopefully that helps?