unclass all the nodes in a dendrogram tree. (Helps in cases when a dendrapply function was used wrongly)

unclass_dend(dend, ...)

Arguments

dend

a dendrogram object

...

not used

Value

The list which was the dendrogram (but without a class)

See also

Examples

# define dendrogram object to play with:
hc <- hclust(dist(USArrests[1:3, ]), "ave")
dend <- as.dendrogram(hc)

itself <- function(x) x
dend <- dendrapply(dend, itself)
unclass(dend) # this only returns a list with
#> [[1]]
#> 'dendrogram' leaf 'Arizona', at height 0 
#> 
#> [[2]]
#> 'dendrogram' with 2 branches and 2 members total, at height 37.17701 
#> 
#> attr(,"members")
#> [1] 3
#> attr(,"midpoint")
#> [1] 0.75
#> attr(,"height")
#> [1] 54.80041
# two dendrogram objects inside it.
str(dend) # this is a great way to show a dendrogram,
#> --[dendrogram w/ 2 branches and 3 members at h = 54.8]
#>   |--leaf "Arizona" 
#>   `--[dendrogram w/ 2 branches and 2 members at h = 37.2]
#>      |--leaf "Alabama" 
#>      `--leaf "Alaska" 
# but it doesn't help us understand how the R object is built.
str(unclass(dend)) # this is a great way to show a dendrogram,
#> List of 2
#>  $ :  ..--leaf "Arizona" 
#>  $ :  ..--[dendrogram w/ 2 branches and 2 members at h = 37.2, midpoint = 0.5]
#>   ..  |--leaf "Alabama" 
#>   ..  `--leaf "Alaska" 
#>  - attr(*, "members")= int 3
#>  - attr(*, "midpoint")= num 0.75
#>  - attr(*, "height")= num 54.8
# but it doesn't help us understand how the R object is built.
unclass_dend(dend) # this only returns a list
#> [[1]]
#> [1] 3
#> attr(,"members")
#> [1] 1
#> attr(,"height")
#> [1] 0
#> attr(,"label")
#> [1] "Arizona"
#> attr(,"leaf")
#> [1] TRUE
#> 
#> [[2]]
#> [[2]][[1]]
#> [1] 1
#> attr(,"label")
#> [1] "Alabama"
#> attr(,"members")
#> [1] 1
#> attr(,"height")
#> [1] 0
#> attr(,"leaf")
#> [1] TRUE
#> 
#> [[2]][[2]]
#> [1] 2
#> attr(,"label")
#> [1] "Alaska"
#> attr(,"members")
#> [1] 1
#> attr(,"height")
#> [1] 0
#> attr(,"leaf")
#> [1] TRUE
#> 
#> attr(,"members")
#> [1] 2
#> attr(,"midpoint")
#> [1] 0.5
#> attr(,"height")
#> [1] 37.17701
#> 
#> attr(,"members")
#> [1] 3
#> attr(,"midpoint")
#> [1] 0.75
#> attr(,"height")
#> [1] 54.80041
#  with two dendrogram objects inside it.
str(unclass_dend(dend)) # NOW we can more easily understand
#> List of 2
#>  $ : int 3
#>   ..- attr(*, "members")= int 1
#>   ..- attr(*, "height")= num 0
#>   ..- attr(*, "label")= chr "Arizona"
#>   ..- attr(*, "leaf")= logi TRUE
#>  $ :List of 2
#>   ..$ : int 1
#>   .. ..- attr(*, "label")= chr "Alabama"
#>   .. ..- attr(*, "members")= int 1
#>   .. ..- attr(*, "height")= num 0
#>   .. ..- attr(*, "leaf")= logi TRUE
#>   ..$ : int 2
#>   .. ..- attr(*, "label")= chr "Alaska"
#>   .. ..- attr(*, "members")= int 1
#>   .. ..- attr(*, "height")= num 0
#>   .. ..- attr(*, "leaf")= logi TRUE
#>   ..- attr(*, "members")= int 2
#>   ..- attr(*, "midpoint")= num 0.5
#>   ..- attr(*, "height")= num 37.2
#>  - attr(*, "members")= int 3
#>  - attr(*, "midpoint")= num 0.75
#>  - attr(*, "height")= num 54.8
# how the dendrogram object is structured...