Reputation: 65
I have a list with a big structure similar to this:
BigList =
[[1]]
[1] matrix
[2] array
[3] data.frame
[4] data.frame
[5] integer
[6] character
...
[26]
[[2]]
[1]
...
[26]
[[3]]
[1]
...
[26]
[[4]]
...
I am trying to get data greater than 10 from element 5 (named "n" in my list) of each list using:
Listsubset = laply(BigList, function(x) x$n[n>10]) Not working
and also use this:
Listsubset = laply(filo_main_data, function(x) x$n >10) Which worked but gave it to me a result of logical information (TRUE or FALSE) and I would like to get which values of n are TRUE.
Upvotes: 0
Views: 811
Reputation: 887391
We can use lapply
BigList[unlist(lapply(BigList, `[[`, "n")) > 10]
Upvotes: 0
Reputation: 389065
You can use Filter
:
Listsubset <- Filter(function(x) x$n > 10, BigList)
Or an alternative with sapply
:
Listsubset <- BigList[sapply(BigList, `[[`, 'n') > 10]
Upvotes: 1