Nikol Simecek wrote:
> Hello
> I am am new to R and any help with the following would be appreciated:
> I have a list (example attached) and I would like to create a new list
> which is a filtered version of this list. I.e I would like a list that
> only contains elements with this value:
>
> Chr 10 : 21853562 - 21855482

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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to