Creating a new list by combining element of previous list in R -


i have list this:

    v = list(a1= 1, a2 = 2, b1 = 3, b2= 4, b3 = 5) 

my desire result creating list :

   v = list(a = c(1, 2), b = c(3, 4, 5)) 

but should mentioned vector v exapmle, can wrote code above example, problem if each time length of ai , biis different, how can wrote function desire result in r?

split(unlist(v), sub("\\d+$", "", names(v))) # $a # a1 a2  #  1  2  #  # $b # b1 b2 b3  #  3  4  5  

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -