[R] Recursive looping of a list in R

Jim Lemon drjimlemon at gmail.com
Sun Aug 9 00:33:54 CEST 2015


Hi Evans,
I'm not sure whether this is what you want, but look at the code in
the listBuilder and listCrawler functions in the crank package.

Jim


On Sun, Aug 9, 2015 at 4:14 AM, Evans <evansochiaga at aims.ac.za> wrote:
> I am trying to creat a list from a loop such that once you loop the value
> obtained is appended onto the list, then you loop through that value to give
> the next elemet of the list and the system continues recusively. To be clear
> I am creating a list to contain elements of the following tree
> probabilities;
> <http://r.789695.n4.nabble.com/file/n4710898/help.png> . The elements of the
> diagram should be presented in a list such that each level of the tree
> represents elements in the list (only the coefficients are of interest). I
> have this code to start with
>
> j <- 0
>
> while(j >= 0){
>
>   j <- j+1
>
>   occlist <- list(1)
>
>   for(i in occlist[[j]]){
>
>     occ_cell <- seq(i, i+1, by = 1)
>
>     occllist <- list(occ_cell)
>
>     occunlist <- as.vector(unlist(occllist, recursive = TRUE))
>
>     occlist[[j]] <- occunlist
>
>     print(occlist)
>
>   }
> }
>
> Any assistance will be highly appreciated. Thanks.
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Recursive-looping-of-a-list-in-R-tp4710898.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list