Conditional row removal based on number of NA's within the row
问题 I am looking to remove rows from my dataset based on two conditions as follows: Remove row if 3 consecutive cells are NA or If four or more cells are NA My sample data: data <- rbind(c(1,1,2,3,4,2,3,2), c(NA,1, NA, 4,1,1,NA,2), c(1,4,6,7,3,1,2,2), c(NA,3, NA, 1,NA,2,NA,NA), c(1,4, NA, NA,NA,4,3,2)) I have researched within the existing questions and found that na.omit or complete.cases can remove rows with NA but as I have conditions, doing further research I have found the following code