r - Convert a nested list to a list -
this question has answer here:
i have brief question, unnest nested list:
mylist <- list(a = list(a=1, b=5), b = list(c= 1, d = 2), c = list(e = 1, f = 3))
expected result is:
> list(a=c(1, 5), b = c(1, 2), c = c(1, 3)) $a [1] 1 5 $b [1] 1 2 $c [1] 1 3
any suggestions?
t
take @ llply
function plyr package
> library(plyr) > llply(mylist, unlist) $a b 1 5 $b c d 1 2 $c e f 1 3
if want rid of names, try:
> lapply(llply(mylist, unlist), unname) $a [1] 1 5 $b [1] 1 2 $c [1] 1 3
Comments
Post a Comment