Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

treeprune

Prune Tree to Given Level


Description

Prune a tree by removing all the branches above a given level.

Usage

treeprune(X, root = 1, level = 0)

Arguments

X

Object of class "linnet" or "lpp".

root

Index of the root vertex amongst the vertices of as.linnet(X).

level

Integer specifying the level above which the tree should be pruned.

Details

The object X must be either a linear network, or a derived object such as a point pattern on a linear network. The linear network must be an acyclic graph (i.e. must not contain any loops) so that it can be interpreted as a tree.

This function removes all vertices for which treebranchlabels gives a string more than level characters long.

Value

Object of the same kind as X.

Author(s)

Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner r.turner@auckland.ac.nz and Ege Rubak rubak@math.aau.dk

See Also

treebranchlabels for calculating the branch labels.

deletebranch for removing entire branches. extractbranch for extracting entire branches.

linnet for creating networks.

Examples

# make a simple tree
  m <- simplenet$m
  m[8,10] <- m[10,8] <- FALSE
  L <- linnet(vertices(simplenet), m)
  plot(L, main="")
  # compute branch labels 
  tb <- treebranchlabels(L, 1)
  tbc <- paste0("[", tb, "]")
  text(vertices(L), labels=tbc, cex=2)
  # prune tree 
  tp <- treeprune(L, root=1, 1)
  plot(tp, add=TRUE, col="blue", lwd=3)

spatstat.linnet

Linear Networks Functionality of the 'spatstat' Family

v2.1-1
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Ottmar Cronie [ctb], Tilman Davies [ctb], Greg McSwiggan [ctb], Suman Rakshit [ctb]
Initial release
2021-03-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.