Converts an rpart::rpart() classification tree into a dichotomous key:
every split becomes a couplet with two leads, and every leaf a result.
Taxa that the tree cannot separate share a leaf and are listed together
("A / B").
Arguments
- fit
An
rpartobject withmethod = "class", e.g. fromgenerateTree().- desc
Title of the key.
- meta
Key/value metadata data frame.
Value
A dimoose object.
Examples
d <- data.frame(
taxon = factor(c("A", "B", "C")),
wings = factor(c("+", "-", "-")),
spots = factor(c("-", "+", "-"))
)
fit <- generateTree(d, "taxon",
params = list(control = rpart::rpart.control(minsplit = 2, minbucket = 1, cp = 0)))
keyFromRpart(fit, "Three taxa")$leads
#> Statement Choice Character Next Taxon
#> 1 1 a wings: + - A
#> 2 1 b wings: - 2
#> 3 2 a spots: + - B
#> 4 2 b spots: - - C