A D
A D

Reputation: 305

Using R lapply on a list to remove elements from the list

I have a list I want to process to remove elements not meeting certain criteria. I'd use a loop but that is too slow so I assume lapply might be better.

assuming the last thing function y does is give a value of 1 or 2 to variable x how would I modify

lapply(list,functiony, z=valueA, a=valueB) to give back a list of only the elements of the list that are of value x=1?

Upvotes: 0

Views: 1529

Answers (1)

Rufo
Rufo

Reputation: 534

Try mylist[sapply(mylist, functiony, z=valueA, a=valueB)==1]

Upvotes: 3

Related Questions