| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/noded_with_condition.R |
| 3 |
\name{noded_with_condition} |
| 4 |
\alias{noded_with_condition} |
| 5 |
\title{Find which nodes satisfies a condition} |
| 6 |
\usage{ |
| 7 |
noded_with_condition( |
| 8 |
dend, |
| 9 |
condition, |
| 10 |
include_leaves = TRUE, |
| 11 |
include_branches = TRUE, |
| 12 |
na.rm = FALSE, |
| 13 |
... |
| 14 |
) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{dend}{a dendrogram dend} |
| 18 |
|
| 19 |
\item{condition}{a function that gets a node and return TRUE or FALSE |
| 20 |
(based on whether or not that node/tree fulfills the "condition")} |
| 21 |
|
| 22 |
\item{include_leaves}{logical. Should leaves attributes be included as well?} |
| 23 |
|
| 24 |
\item{include_branches}{logical. Should non-leaf (branch node) |
| 25 |
attributes be included as well?} |
| 26 |
|
| 27 |
\item{na.rm}{logical. Should NA attributes be REMOVED from the resulting vector?} |
| 28 |
|
| 29 |
\item{...}{passed to the condition function} |
| 30 |
} |
| 31 |
\value{ |
| 32 |
A logical vector with TRUE/FALSE, specifying for each of the dendrogram's nodes if it fulfills the condition or not. |
| 33 |
} |
| 34 |
\description{ |
| 35 |
Goes through a tree's nodes in order to return a vector |
| 36 |
with whether (TRUE/FALSE) each node satisies some condition (function) |
| 37 |
} |
| 38 |
\examples{ |
| 39 |
\dontrun{ |
| 40 |
|
| 41 |
library(dendextend) |
| 42 |
|
| 43 |
set.seed(23235) |
| 44 |
ss <- sample(1:150, 10) |
| 45 |
|
| 46 |
# Getting the dend dend |
| 47 |
dend <- iris[ss, -5] \%>\% |
| 48 |
dist() \%>\% |
| 49 |
hclust() \%>\% |
| 50 |
as.dendrogram() |
| 51 |
dend \%>\% plot() |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
# this is the basis for branches_attr_by_labels |
| 56 |
has_any_labels <- function(sub_dend, the_labels) any(labels(sub_dend) \%in\% the_labels) |
| 57 |
cols <- noded_with_condition(dend, has_any_labels, |
| 58 |
the_labels = c("126", "109", "59") |
| 59 |
) \%>\% |
| 60 |
ifelse(2, 1) |
| 61 |
set(dend, "branches_col", cols) \%>\% plot() |
| 62 |
|
| 63 |
# Similar to branches_attr_by_labels - but for heights! |
| 64 |
high_enough <- function(sub_dend, height) attr(sub_dend, "height") > height |
| 65 |
cols <- noded_with_condition(dend, high_enough, height = 1) \%>\% ifelse(2, 1) |
| 66 |
set(dend, "branches_col", cols) \%>\% plot() |
| 67 |
} |
| 68 |
|
| 69 |
} |
| 70 |
\seealso{ |
| 71 |
\link{branches_attr_by_labels}, \link{get_leaves_attr}, \link{nnodes}, \link{nleaves} |
| 72 |
} |