I feel like I should be able to do this with filter or subset, but can't figure out how.
How do I remove a row if three or more of the cells in that row are "NA"?
So in this dataset, rows with titles 1A-C2 and 3A-C2 would be removed.
my_data <- data.frame(Title = c("1A-C2", "1D-T2", "1F-T1", "1E-C2", "3A-C2", "3F-T2"),
Group1 = c(NA, 10, 2, 9, NA, 4), Group2 = c(1, 3, 6, 1, NA, 3), Group3=c(NA, 3, 3, 8, NA, 4), Group4=c(NA, NA, 4, 5, 1, 7), Group5=c(1, 4, 3, 3, 9, NA), Group6=c(NA, 4, 5, 6, 1, NA))
Thank you!!
With Base R
,
my_data[rowSums(is.na(my_data))<3,]
gives,
Title Group1 Group2 Group3 Group4 Group5 Group6
2 1D-T2 10 3 3 NA 4 4
3 1F-T1 2 6 3 4 3 5
4 1E-C2 9 1 8 5 3 6
6 3F-T2 4 3 4 7 NA NA