[英]hclust: how to plot in R by grouping variables
是否可以在 R 中將匯總與 hclust 一起使用?
S %>% summarise(hc = hclust(dist()))
這給了我一個錯誤:
Error: Problem with `summarise()` column `hc`.
ℹ `hc = hclust(dist())`.
x argument "x" is missing, with no default
ℹ The error occurred in group 1: country = ch.
你需要的是一個nest()
來按組折疊你的 dataframe 然后map
使用 iris 遍歷你的嵌套數據幀:
res = iris %>% nest(data = !Species) %>%
mutate(hc=map(data,~hclust(dist(.x))))
# A tibble: 3 x 3
Species data hc
<fct> <list> <list>
1 setosa <tibble [50 × 4]> <hclust>
2 versicolor <tibble [50 × 4]> <hclust>
3 virginica <tibble [50 × 4]> <hclust>
plot(res$hc[[1]])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.