Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- purge <- function(x,.p){
- x <- x[!sapply(x,.p)]
- if(inherits(x,'list')){
- lapply(x,purge,.p = .p)
- }else{
- x
- }
- }
- x <- list(NULL,list(a=list(1,NULL)),list(b=list(list(3,NA),2)))
- purge(x,.p = is.null)
- purge(x,.p=function(y) is.null(y)||is.na(y))
Add Comment
Please, Sign In to add comment