get unique entries from a complex list in r -
i have list of lists:
$markers mi chr phys.pos group 19 mg001 8 4803507 1 20 mg002 8 4841939 1 3 mg003 8 5268581 2 1 mg004 8 5278404 2 6 mg005 8 8352013 3 7 mg006 8 8352443 3 9 mg008 8 8354875 3 10 mg009 8 8356039 4 11 mg010 8 8357610 4 13 mg012 8 8361049 5 14 mg013 8 8361845 5 15 mg014 8 1640281 6 16 mg015 8 1640663 7 $plants plant group 9 dl750 1 11 d827 1 17 dl26 1 25 d901 2 30 dr202 3 35 d356 3 52 f015 4
i list of entries unique in "group", , list of leftovers. results expected as:
(a) unique list:
$markers mi chr phys.pos group 19 mg001 8 4803507 1 3 mg003 8 5268581 2 6 mg005 8 8352013 3 10 mg009 8 8356039 4 13 mg012 8 8361049 5 15 mg014 8 1640281 6 16 mg015 8 1640663 7 $plants plant group 9 dl750 1 25 d901 2 30 dr202 3 52 f015 4
(b) leftover list:
$markers mi chr phys.pos group 20 mg002 8 4841939 1 1 mg004 8 5278404 2 7 mg006 8 8352443 3 9 mg008 8 8354875 3 11 mg010 8 8357610 4 14 mg013 8 8361845 5 $plants plant group 11 d827 1 17 dl26 1 35 d356 3
appreciate helps.
if mylist
list, simply
unique <- lapply(mylist, function(x) x[!duplicated(x$group), ]) unique # $markers # mi chr phys.pos group # 19 mg001 8 4803507 1 # 3 mg003 8 5268581 2 # 6 mg005 8 8352013 3 # 10 mg009 8 8356039 4 # 13 mg012 8 8361049 5 # 15 mg014 8 1640281 6 # 16 mg015 8 1640663 7 # # $plants # plant group # 9 dl750 1 # 25 d901 2 # 30 dr202 3 # 52 f015 4 leftovers <- lapply(mylist, function(x) x[duplicated(x$group), ]) leftovers # $markers # mi chr phys.pos group # 20 mg002 8 4841939 1 # 1 mg004 8 5278404 2 # 7 mg006 8 8352443 3 # 9 mg008 8 8354875 3 # 11 mg010 8 8357610 4 # 14 mg013 8 8361845 5 # # $plants # plant group # 11 d827 1 # 17 dl26 1 # 35 d356 3
Comments
Post a Comment