R中嵌套列表的直方图

Histogram from nested list in R

我有一个类似于此的嵌套列表

df <- data.frame(width = c(1:5),height = c(1:5),depth = c(1:5))
list <- list(df,df*2,df*5,df*1.3)

我想在 base R 或 ggplot 中制作每个列表最终高度的直方图。我试过了

hist(tail(list[[1:4]]$height,1))

产生

Error in list[[1:4]] : recursive indexing failed at level 3

以及

for (i in 1:4){
hist(tail(list[[i]]$height,1))
}

生成单个观察的 4 个独立直方图。我试图避免简单地在 hist() 中列出每个观察结果,例如

hist(tail(list[[1]]$height,1),tail(list[[2]]$height,1),tail(list[[3]]$height,1))

因为我的实际数据有4个以上的子列表。我怎样才能优雅地实现这一目标?

如果我们要提取 'height' 的最后一个元素,请使用 sapply 遍历 list,提取 ($) 'height' 列,获取 tail 值(sapply - returns a vector 此处)然后应用 hist

hist( sapply(list, function(x) tail(x$height, 1)))