Guest User

Untitled

a guest
May 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1. purge <- function(x,.p){
  2.  
  3. x <- x[!sapply(x,.p)]
  4.  
  5. if(inherits(x,'list')){
  6. lapply(x,purge,.p = .p)
  7. }else{
  8. x
  9. }
  10.  
  11. }
  12.  
  13. x <- list(NULL,list(a=list(1,NULL)),list(b=list(list(3,NA),2)))
  14.  
  15. purge(x,.p = is.null)
  16.  
  17. purge(x,.p=function(y) is.null(y)||is.na(y))
Add Comment
Please, Sign In to add comment