Re: [R] flatten a list

2015-09-29 Thread Giorgio Garziano
To mention also: temp <- list(1:3, list(letters[1:3], duh= 5:8), zed=15:17) library(rlist) list.flatten(temp) [[1]] [1] 1 2 3 [[2]] [1] "a" "b" "c" $duh [1] 5 6 7 8 $zed [1] 15 16 17 --- Giorgio Garziano [[alternative HTML version deleted]] ___

Re: [R] flatten a list

2015-09-29 Thread Giorgio Garziano
If you need further info on flattening a list, check this out: http://stackoverflow.com/questions/8139677/how-to-flatten-a-list-to-a-list-without-coercion/8139959#8139959 [[alternative HTML version deleted]] __ R-help@r-project.org mailing l

Re: [R] flatten a list

2015-09-29 Thread Gabor Grothendieck
> do.call(c, lapply(temp, function(x) if (is.list(x)) x else list(x))) [[1]] [1] 1 2 3 [[2]] [1] "a" "b" "c" $duh [1] 5 6 7 8 $zed [1] 15 16 17 On Tue, Sep 29, 2015 at 11:00 AM, Therneau, Terry M., Ph.D. < thern...@mayo.edu> wrote: > I'd like to flatten a list from 2 levels to 1 level. This

[R] flatten a list

2015-09-29 Thread Therneau, Terry M., Ph.D.
I'd like to flatten a list from 2 levels to 1 level. This has to be easy, but is currently opaque to me. temp <- list(1:3, list(letters[1:3], duh= 5:8), zed=15:17) Desired result would be a 4 element list. [[1]] 1:3 [[2]] "a", "b", "c" [[duh]] 5:8 [[zed]] 15:17 (Preservation of the names is n

Re: [R] flatten a list of lists

2013-10-17 Thread Michael Friendly
= chr "foo" - attr(*, "class")= chr "foolist" - David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message- From: r-help-boun...@r-project.org [mailto:r-hel

Re: [R] flatten a list of lists

2013-10-17 Thread David Carlson
ct.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ista Zahn Sent: Thursday, October 17, 2013 8:23 AM To: Michael Friendly Cc: R-help Subject: Re: [R] flatten a list of lists unlist(mfoo, recursive = FALSE) gets you pretty close. Best, Ista On Thu, Oct 17, 2013 at 9:15 AM, Michael Friendl

Re: [R] flatten a list of lists

2013-10-17 Thread Duncan Murdoch
On 17/10/2013 9:15 AM, Michael Friendly wrote: I have functions that generate lists objects of class "foo" and lists of lists of these, of class "foolist", similar to what is shown below. You can use c() to join lists. So in the example below, c(mfoo$A, mfoo$B) will give you a list with the

Re: [R] flatten a list of lists

2013-10-17 Thread Ista Zahn
unlist(mfoo, recursive = FALSE) gets you pretty close. Best, Ista On Thu, Oct 17, 2013 at 9:15 AM, Michael Friendly wrote: > I have functions that generate lists objects of class "foo" and lists of > lists of these, of class > "foolist", similar to what is shown below. > > How can I flatten some

[R] flatten a list of lists

2013-10-17 Thread Michael Friendly
I have functions that generate lists objects of class "foo" and lists of lists of these, of class "foolist", similar to what is shown below. How can I flatten something like this to remove the top-level list structure, i.e., return a single-level list of "foo" objects, of class "foolist"? foo