我有一个名为Buffer_list
的大型列表(20个元素,4.2Mb),我将其转换为如下所示的数据帧(现在为Buffer_norm
):
#changing the List to a data frame with max for the biggest element
max.length <- max(sapply(Buffer_list, length))
List_norm <- lapply(Buffer_list, function(v) { c(v, rep(NA, max.length-length(v)))})
Buffer_norm <- as.data.frame(List_norm)
names(Buffer_norm) = c(1:20)
现在,每列的长度相同(57.443行),较短列表的NA相同。
当查看data.frame时,它告诉我所有值都是数字。尝试此操作时相同:
sapply(Buffer_norm, mode)
1 2 3 4 5 6 7 8 9 10 11 12 13
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric"
14 15 16 17 18 19 20
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric"
> sapply(Buffer_norm, class)
1 2 3 4 5 6 7 8 9 10 11 12 13
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric"
14 15 16 17 18 19 20
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric"
显示
时,这些值不是数字plot(density(Buffer_norm))
density.default(Buffer_norm)中的错误:参数“ x”必须为数字 我想为y轴从0到1的每一列本身绘制data.frame的密度直方图。必须牢记将列表转换为data.frame所增加的NA!
我尝试遵循此规则:R Normalize then plot two histograms together in R 和ggplot2 histogram with density curve that sums to 1 没有任何成功!