I have a list of list of lists in R. I want to remove the ones that are of length zero.
What I have tried so far is:
for (i in 1:length(test)) {
keep <- rep(T, length(test))
for (j in 1:length(test[[i]])) {
if (length(test[[i]][[j]]) == 0) {
keep[[j]] <- F
}
}
test2[i] <- test2[i][keep]
}
Here is some example data (edited):
test <- list("Section 1" = list("A" = list(), "B" = list("1x1" = "23", "1x2" = "24"), C = list("2x1" = "78")),
"Section 2" = list("A" = list(), "B" = list("1x1" = "23", "1x2" = "24"), C = list("2x1" = "78")))
I would like a way to remove the "A" list in both section 1 and section 2 since both are length 0