Group a list of list by nested size in R -


i have function generates subsets set, in list of list. group them size, , have list (indexed different sizes), of list (for collection of subsets), of list (for subset)

this code generating input (the list of subsets)

library(plyr)  library(ggplot2)   all.subsets <- function(set) {   n <- length(set)                                     bin <- expand.grid(rlply(n, c(f, t)))                                  mlply(bin, function(...) { set[c(...)] }) }  p3 <- all.subsets(c("a","b","c"))   

now i'd have instead of whole list of subsets, collection indexed size size, , gives me collection of subsets of size.

what r way perform ?

to nested list of length equal 1 can following:

p3[lapply(p3,length) ==1]   ## elements size equal 1  $`2` [1] "a"  $`3` [1] "b"  $`5` [1] "c" 

now, can use group nested lists lengths. loop(lapply) on unique lengths, , perform above statement each length :

lapply(unique(unlist(lapply(p3,length))),        function(x) p3[lapply(p3,length) ==x] ) 

Comments