slice: Cut a tree-like object into groups numbered in tree order

Description Usage Arguments Value Author(s) See Also Examples

View source: R/slice.R

Description

In comparison with cutree, the groups are numbered from left to right as per the tree when plotted in its standard horizontal form. Note also that the return value will have the leaves sorted in dendrogram order.

Usage

1
slice(x, k = NULL, h = NULL, ...)

Arguments

x

tree like object

k

an integer scalar with the desired number of groups

h

numeric scalar with height where the tree should be cut

...

Additional parameters passed to methods

Value

a named vector with group memberships

Author(s)

jefferis

See Also

cutree,cut.dendrogram,rect.hclust

Examples

1
2
3
4
5
hc <- hclust(dist(USArrests), "ave")
# return groups, leaves ordered by dendrogram
slice(hc,k=5)
# return groups, leaves ordered as originally passed to hclust
slice(hc,k=5)[order(hc$order)]

Example output

       Florida North Carolina     California       Maryland        Arizona 
             1              1              2              2              2 
    New Mexico       Delaware        Alabama      Louisiana       Illinois 
             2              2              2              2              2 
      New York       Michigan         Nevada         Alaska    Mississippi 
             2              2              2              2              2 
South Carolina     Washington         Oregon        Wyoming       Oklahoma 
             2              3              3              3              3 
      Virginia   Rhode Island  Massachusetts     New Jersey       Missouri 
             3              3              3              3              3 
      Arkansas      Tennessee        Georgia       Colorado          Texas 
             3              3              3              3              3 
         Idaho       Nebraska       Kentucky        Montana           Ohio 
             4              4              4              4              4 
          Utah        Indiana         Kansas    Connecticut   Pennsylvania 
             4              4              4              4              4 
        Hawaii  West Virginia          Maine   South Dakota   North Dakota 
             5              5              5              5              5 
       Vermont      Minnesota      Wisconsin           Iowa  New Hampshire 
             5              5              5              5              5 
       Alabama         Alaska        Arizona       Arkansas     California 
             2              2              2              3              2 
      Colorado    Connecticut       Delaware        Florida        Georgia 
             3              4              2              1              3 
        Hawaii          Idaho       Illinois        Indiana           Iowa 
             5              4              2              4              5 
        Kansas       Kentucky      Louisiana          Maine       Maryland 
             4              4              2              5              2 
 Massachusetts       Michigan      Minnesota    Mississippi       Missouri 
             3              2              5              2              3 
       Montana       Nebraska         Nevada  New Hampshire     New Jersey 
             4              4              2              5              3 
    New Mexico       New York North Carolina   North Dakota           Ohio 
             2              2              1              5              4 
      Oklahoma         Oregon   Pennsylvania   Rhode Island South Carolina 
             3              3              4              3              2 
  South Dakota      Tennessee          Texas           Utah        Vermont 
             5              3              3              4              5 
      Virginia     Washington  West Virginia      Wisconsin        Wyoming 
             3              3              5              5              3 

dendroextras documentation built on May 2, 2019, 2:10 p.m.