[R] as.function parameters
Jason Edgecombe
jason at rampaginggeek.com
Thu May 17 20:51:13 CEST 2012
On 05/17/2012 06:30 AM, jackl wrote:
> Hi..
>
> Ok here is an example on how I wanted the tree to be implemented in R:
>
> - the tree is, as you wrote, saved as a list of different tree levels
> - each tree level is also saved as a list of different nodes in that
> specific level
> - and for the last part, each node is then saved as a list of functions
>
> example:
> tree<- list(root, lvl1, lvl2)
> root<- list(node00)
> lvl1<- list(node10, node11)
> lvl2<- list(node20, node21, node22)
>
> node00<- list(f1,f2,f3)
> node10<- list(f1,f2,f3)
> node11<- list(f1,f2,f3)
> ..
>
> note: I wrote f1, f2 and f3 in each node because it is the same function,
> just with the different parameter, the stock price at that node.
>
> I tried implementing a tree manually and I found out that the
> independences between one node and each childnode cause a
> heavy computation power.. (the function f3 contains f3 of the
> two childnodes and so on..)
> example:
> node11$f3<- max(node11$f2, node21$f3, node22$f3)
>
> Im facing this problem even with a tree with 'only' 4-5 layers..
>
> best thanks for any answers
>
Hi,
First, what problem are you trying to solve? A tree structure is not a
problem... it's a tool, to solve a problem.
Second, a tree data structure is simply a simplified graph structure.
There are many packages in R that deal with and store graph structures.
Two that come to mind are igraph
<http://cran.r-project.org/web/packages/igraph/index.html> and sna
<http://cran.r-project.org/web/packages/sna/>
Since those packages can handle graphs, they can handle trees as well.
As an added bonus, the code is already available and well-tested.
If memory usage is a concern, then look into using a sparse matrix
implementation.
Jason
More information about the R-help
mailing list