I have a complex list and need to select a subset from it, based on the value of a boolean element (I need records with hidden
value e
Data frames are indexed using two numbers. To only select rows, you need to do:
data$startups[data$startups$hidden == FALSE, ]
The example data in the question is a list of length 3 which we shall call L
. Each of its components is itself a list and one component of each of these sublists is hidden
. We can extract the hidden
components of the sublists into a logical vector called hidden
. Using that logical vector we can subset the original list L
giving a new list containing only those sublists with a hidden
component of TRUE
.
hidden <- sapply(L, "[[", "hidden") # create logical vector hidden
L[hidden]
For the data provided we get a list with one component:
> length(L[hidden])
[1] 1
and if we knew that there were only one component then L[hidden][[1]]
or L[[which(hidden)]]
would give that single component.