This question already has answers here:
Removing empty rows of a data file in R
(5 answers)
How to remove rows where columns satisfy certain condition in data frame
(2 answers)
Closed 2 years ago.
I have a data frame where only some of the rows have all NA. How do I loop through and delete all these rows? I tried na.omit() but that doesn't work. In this example I need rows 3 and 5 removed
x1 <- c("Bob", "Mary","","Jane","")
x2 <- c("Bob","Mary","","Jane","")
x3 <- c("Bob", "Mary","","Jane","")
x4 <- c("Bob","Mary","","Jane","")
df <- data.frame(x1,x2,x3,x4)
df <- df %>% na.omit()