Skip to content

Instantly share code, notes, and snippets.

@jlehtoma
Created August 26, 2014 19:41
Show Gist options
  • Save jlehtoma/1c6f22245471af870f2a to your computer and use it in GitHub Desktop.
Save jlehtoma/1c6f22245471af870f2a to your computer and use it in GitHub Desktop.
Check if any of the elements in a list within a list is NULL
library(rlist)
x <- list(list("ID"=1, "var1"="B", "var2"="D"),
list("ID"=2, "var1"="F", "var2"="H"),
list("ID"=3, "var1"="I", "var2"=NULL))
# rlist approach - returns FALSE
list.any(x, l ~ is.null(l))
# 2-level lapply - returns TRUE
any(unlist(lapply(x, function(x) lapply(x, function(x) ifelse(is.null(x), TRUE, FALSE)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment