Thanks Wolfgang and Thomas.
Indeed, looping recursively over the rows of the merge matrix is simple.


On 12 May 2010 01:56, Thomas Girke <thomas.girke@ucr.edu> wrote:

> Try:
>
> ?dendrapply
>
> Thomas
>
> On Wed, May 12, 2010 at 12:34:11AM +0200, Wolfgang Huber wrote:
> > On 11/05/10 14:49, Anthony Ferrari wrote:
> > >Hi all,
> > >
> > >Does exist a package  that allows one to recursively apply a custom
> > >function
> > >to nodes in a binary tree (from hclust) from leaves to the root ?
> > >A kind of "tree_apply" ?
> > >Ideally, after that, we could easily retrieve the value of the function
> at
> > >each node and the leaves IDs under that node.
> > >
> > >Thank you.
> > >
> > >AF
> > >
> > >
> >
> > Dear Anthony,
> >
> > /* this would be better for R-help.... */
> >
> > perhaps there is already a solution out there, but the task is so simple
> > that you may not need a package.
> >
> > For trees that are represented as lists of lists, something like the
> > below code example would work.
> >
> > For the representation used by hclust, you could write a similar
> > function that loops over the rows of the "merge" matrix (see the hclust
> > man page).
> >
> >
> > tree = list(a = list( A=1,  B=2),
> >             b = list( A=list(x=3, y=4, z=5),
> >                       B=list(x=6, y=7),
> >                       C=8),
> >             c = 9)
> >
> > traverse = function(x, f)
> >   if (is.list(x)) lapply(x, traverse, f=f) else f(x)
> >
> > traverse(tree, f=function(x) x+1)
> >
> >
> >
> >
> > Wolfgang Huber
> > EMBL
> > http://www.embl.de/research/units/genome_biology/huber
> >
> > _______________________________________________
> > Bioconductor mailing list
> > Bioconductor@stat.math.ethz.ch
> > https://stat.ethz.ch/mailman/listinfo/bioconductor
> > Search the archives:
> > http://news.gmane.org/gmane.science.biology.informatics.conductor
> >
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor@stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor
>

	[[alternative HTML version deleted]]

