Skip to content

Instantly share code, notes, and snippets.

@kleinlennart
Last active October 21, 2020 14:17
Show Gist options
  • Save kleinlennart/0796d2c058231f0ed922b134577145a1 to your computer and use it in GitHub Desktop.
Save kleinlennart/0796d2c058231f0ed922b134577145a1 to your computer and use it in GitHub Desktop.
Logically index list of lists in R
# Length of sublist
dat$media_url[sapply(dat$media_url, function(x) length(x) == 2)]
# not empty sublists
dat$media_url[sapply(dat$media_url, function(x) !is.na(x))]
dat$media_url[sapply(dat$media_url, function(x) all(!is.na(x)))] # multiple NA values per sublist
na.omit.list <- function(list) {
return(list[sapply(list, function(x) all(!is.na(x)))])
}
# sapply returns logical index vector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment