Skip to content
Prev 172531 / 398503 Next

Filtering R lists

Nikol Simecek wrote:
Filter provides a generic approach to filtering:

    Filter(x=<your list>,
        f=function(element)
            <does element contain 'Chr 10 : 21853562 - 21855482'?>)

where you have to implement the filtering function.

if each element in your list is a string (a character vector of length
1), you can also use grep:

    grep('Chr 10 : 21853562 - 21855482', <your list>, value=TRUE)

if each element in your list is a character vector, a list, a data
frame, or something else (not just a single string), you may use a
combination of grep and lapply, but i think the Filter approach is in
this case cleaner.

see ?Filter and ?grep.

vQ