Last active
October 21, 2020 14:17
-
-
Save kleinlennart/0796d2c058231f0ed922b134577145a1 to your computer and use it in GitHub Desktop.
Logically index list of lists in R
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
# 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