[R] split list

Bert Gunter gunter.berton at gene.com
Thu Mar 29 19:07:17 CEST 2012


Here's a more "minimalist" and perhaps faster approach (asit uses indexing)

Let "gl" be the the vector with the gene list.

omit <- gl == "batch"
yourlist <- split( gl[omit], ,cumsum(omit)[!omit])

Cheers,
Bert

On Thu, Mar 29, 2012 at 9:25 AM, Martin Morgan <mtmorgan at fhcrc.org> wrote:
> On 03/29/2012 08:18 AM, konika chawla wrote:
>>
>> Hi
>> Is there a function like splitstr, for splitting lists?
>> I want to divide a list of gene names based on a recurring value like
>> "batch"
>> the list is like
>>
>> [1,] "AT4G25480"
>> [2,] "AT3G20810"
>> [3,] "AT2G46670"
>> [4,] "AT4G27310"
>> [5,] "batch"
>> [6,] "AT1G04570"
>> [7,] "AT5G62360"
>> [8,] "AT2G31380"
>> [9,] "AT3G54500"
>> [10,] "AT2G36220"
>> [11,] "batch"
>> [12,] "AT5G06980"
>> [13,] "AT2G46790"
>> [14,] "AT3G55580"
>> [15,] "AT1G73480"
>> [16,] "AT5G54470"
>> [17,] "AT1G07180"
>> I want to split it in three gene lists, and remove the "batch"
>
>
> Hi --
>
> along the lines of
>
>  split(v, cumsum(v == "batch"))
>
> where the first element of all groups except the first will be "batch", and
> would need to be filtered.
>
>   Map(function(elt) if (elt[1] == "batch") elt[-1] else elt,
>       split(v, cumsum(v == "batch")))
>
> Martin
>
>> Any ideas?
>> Thanks
>> Konika
>>
>> ______________________________________________
>> R-help at 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.
>
>
>
> --
> Computational Biology
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109
>
> Location: M1-B861
> Telephone: 206 667-2793
>
> ______________________________________________
> R-help at 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list