TreeData

TreeData[tree]

extracts the data in the root of tree.

TreeData[tree,pos]

extracts the data of subtrees at positions specified by pos.

Details

  • In TreeData[tree,pos], tree should be a valid Tree object.
  • The position specifications used by TreeData have the same form as those returned by TreePosition and used in functions such as TreeExtract.
  • The following positions can be used for pos:
  • ithe i^(th) child
    -ithe i^(th)child from the end
    {i1,i2,}the list of children at positions i1, i2,
    m;;nchildren m through n
    TreeLevel[levelspec]the subtrees on levels specified by levelspec
    TreeCases[pattern]the subtrees with data matching pattern
    TreeSelect[crit]the subtrees for which crit gives True
    TreeDatathe data in the tree
  • TreeData[tree,All] is equivalent to TreeData[tree,TreeLevel[{1}]].
  • In TreeData, position 0 is equivalent to TreeData.

Examples

open allclose all

Basic Examples  (4)

Extract the data in a tree:

Extract the data of the second child of a tree:

Extract the data of a subtree:

Extract the data of multiple subtrees:

Scope  (7)

Extract the data of the first child:

Extract the data of the second-to-last child:

Extract a span of data:

Extract the data of several subtrees using different position specifications:

Extract data by level:

Extract data matching a pattern:

Extract the data of subtrees with exactly two children:

Properties & Relations  (1)

Extract the data of subtrees given by TreePosition:

Possible Issues  (1)

TreeData[tree,{}] returns an empty list because the list of positions is empty:

TreeData[tree,{{}}] extracts the data at position {}, which is the root:

Wolfram Research (2021), TreeData, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeData.html.

Text

Wolfram Research (2021), TreeData, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeData.html.

BibTeX

@misc{reference.wolfram_2021_treedata, author="Wolfram Research", title="{TreeData}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/TreeData.html}", note=[Accessed: 26-September-2021 ]}

BibLaTeX

@online{reference.wolfram_2021_treedata, organization={Wolfram Research}, title={TreeData}, year={2021}, url={https://reference.wolfram.com/language/ref/TreeData.html}, note=[Accessed: 26-September-2021 ]}

CMS

Wolfram Language. 2021. "TreeData." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TreeData.html.

APA

Wolfram Language. (2021). TreeData. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TreeData.html