Created
August 26, 2014 19:41
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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