Reputation: 73
I'm trying to remove elements smaller than a given number from the vectors contained in a list. I manage to find exactly which elements in the vector meet my criteria, but somehow I'm failing to select them.
myList <- list(1:7,4:7,5:10)
lapply(myList, function(x)`>`(x ,5))
...
Rmagic
...
desiredoutput <- list(6:7,6:7,6:10)
I'm sure it's something to do with `[` but I can't figure it out and searching for this problem is a nightmare.
Upvotes: 0
Views: 43
Reputation: 887078
We need to extract the elements based on the logical index (x>=6
)
lapply(myList, function(x) x[x>= 6])
Upvotes: 1