I have got a large list (20 elements, 4.2Mb) called Buffer_list
, which I converted into a data frame (now Buffer_norm
) like this:
#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)
Every column is now of the same length (57.443 rows) with NAs for the shorter lists.
When viewing the data.frame, it shows me, that all values are numeric. The same when I try this:
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"
Whereas it shows me, that the values are not numeric, when
plot(density(Buffer_norm))
Error in density.default(Buffer_norm) : argument 'x' must be numeric I would like to plot a density histogram of the data.frame for every column itself with a y axis from 0 to 1. The added NAs from converting the list to a data.frame have to be kept in mind!
I tried to follow this: R Normalize then plot two histograms together in R and ggplot2 histogram with density curve that sums to 1 without any success!