I have this dataframe (df
):
df <- structure(list(id = c("A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L"), name = c("Sam", "Dave", NA, "Alan", "Ted",
"Ana", NA, NA, "Max", NA, "Walt", NA), age = c(28, 32, NA, NA,
23, NA, 21, NA, NA, 22, 21, NA), height = c(NA, 161, NA, 168,
167, NA, 166, NA, 158, 171, NA, NA)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -12L))
I want to remove rows that have all cells empty except for the id
column. There could be any number of columns in the data. This df
has only 3 columns (id
excluding). This is the final data frame final
:
final <- structure(list(id = c("A", "B", "D", "E", "F", "G", "I", "J",
"K"), name = c("Sam", "Dave", "Alan", "Ted", "Ana", NA, "Max",
NA, "Walt"), age = c(28, 32, NA, 23, NA, 21, NA, 22, 21), height = c(NA,
161, 168, 167, NA, 166, 158, 171, NA)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -9L))
Is it possible with base R
or the tidyverse
package?