[英]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.