简体   繁体   English

如果长度,从列表中的列表中删除列表

[英]Remove list from lists in list if length

I have this 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 like to remove the elements (lists), which length are less than three (<3). 我想删除长度小于三(<3)的元素(列表)。 I tried double lapply to get a[[i]][[j]] and <- NULL, but I got lists only with NULL. 我尝试了双重lapply来获得[[i]] [[j]]和< - NULL,但是我只获得了带有NULL的列表。 Like 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 you for any help... 感谢您的任何帮助...

How about this? 这个怎么样?

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

or 要么

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM