[R] Recursive looping of a list in R

Evans evansochiaga at aims.ac.za
Sat Aug 8 20:14:00 CEST 2015


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.



More information about the R-help mailing list