简体   繁体   English

R.按逻辑从列表中提取列表

[英]R. Extract list from list by logic

I have a list of list containing logical TRUE / FALSE . 我有一个包含逻辑TRUE / FALSE的列表的列表。 How can I extract only lists containing a TRUE value? 如何仅提取包含TRUE值的列表?

Here's my list: 这是我的清单:

jorgelist
# [[1]]
# [1] FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
#
# [[2]]
# [1] FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
#
# [[3]]
# [1] FALSE FALSE FALSE  TRUE

If we want to get a logical vector based on any TRUE values in the list elements, 如果我们想根据获得的逻辑载体any在真值list元素,

i1 <- sapply(jorgelist, any)

This vector can be used to extract the elements from another list of same length vector可用于从另一个相同length list中提取元素

anotherlst[i1]

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

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