Thursday, 17 December 2015

Appending Items to List in R

A very common programming problem is that a function must return a list of objects (itmes like trees...).
In R, we can do something like the following:

func_????? <- function ( ... )
{
    ret_TreeList = list()

    for(i in 1: ?????)
    {
        if(...)
        {
             ret_TreeList[[i]] = something
        }
        else(...)
        {
             ret_TreeList[[i]] = something else
        } 
        
    }

    return(ret_TreeList)
}

Then we cna use it like this:

>TreeList = func_?????(...)
>TreeList[3]

Hope it helps ;-}

No comments:

Post a Comment