r - Remove list from lists in list if length -


i have list:

a <- list(list(c("sam1", "control"), c("sam1", "latanoprost free acid", "gsm6683", "gsm6684"), c("sam1", "prostaglandin f2alpha", "gsm6687", "gsm6688")), list(c("sam2", "control"), c("sam2", "latanoprost free acid", "gsm6681", "gsm6682"), c("sam2", "prostaglandin f2alpha", "gsm6685", "gsm6686"))) 

i'd remove elements (lists), length less 3 (<3). tried double lapply a[[i]][[j]] , <- null, got lists null. this:

b <- lapply(seq(length(a)),function(i){   lapply(seq(length(a[[1]])),function(j){     if(length(a[[i]][[j]]) < 3) {a[[i]][[j]] <- null}   }) }) 

thank help...

how this?

lapply(a, function(x) x[sapply(x, length) >= 3]) 

or

lapply(a, filter, f = function(x) length(x) >= 3) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -