[R] How to express a tree?
Duncan Temple Lang
duncan at wald.ucdavis.edu
Tue Oct 27 23:50:25 CET 2009
Jim Lemon wrote:
> On 10/28/2009 04:06 AM, Hesen Peng wrote:
>> Hello everybody,
>>
>> I'm write a function whose output represents a tree. Can anyone please
>> recommend me some data structure in R which are good for expressing a
>> tree? The possible idea I'm having in my mind is to represent the
>> whole tree as a list in which a sublist (an element to the main list)
>> contains all its corresponding branches. Is there any simpler way of
>> doing this? Thank you very much.
>>
> Hi Hesen,
> This is the approach used in the listBuilder function in the crank
> package. It may be of use to you.
Lists of lists is very natural. It is "hard" to find
the parent and ancestors give a particular sub-tree,
i.e. walk up the tree, should that be an issue.
The XML package also provides various implementations of trees
in R (as well as in C) using
list of lists
environments
parallel vectors of
nodes, parent indices, child indices.
It might be worth a look to see alternatives.
D.
>
> Jim
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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