Saturday 15 May 2010

r - Select list element based on their name -


I have a named list of vectors that represents events occurring from 2 samples, "A" and "B" ":

  l.temp & lt; - List (SF1_T_A = C (Representative (1:10), SF2_ T_A = C (Representative (9:15)), SF1_ T_b = C (Representative (8:12)) L.temp $ SF1_t_A [1] 1 2 3 4 5 6 7 8 9 10 $ SF2_t_A [1] 9 10 11 12 13 14 15 $ SF1_t_B [1] 8 9 10 11 12   

Now I only I want to select the elements of the list which were from the sample "A" or "B", I could go about doing this with a loop, but on the basis of using this type of list around the ply It depends, and the variations that I have yet to do Has tried:

  llply (l.temp, function (l) {if ((unlist (strsplit (names (l), "_")) [3]) == " A (error) (List (L (L), A () (return (L)}})   

This error I am receiving:

  "_") In error (Stripspit (name (LLS), "_"): Error in evaluating argument 'x' in choosing a method for function 'unlist': character logic   

Help is appreciated on what I am doing wrong.

You list You can find patterns in names that give you an index:

  grep ("_ A $", name (l.temp))   

And then use it in the subset:

  l.temp [grep ("_ A $", name (l.temp))]    

No comments:

Post a Comment