I have a list of pixel image objects from spatstat.geom (see example data below) and want to melt them into one data.frame. I do it with reshape::melt and it works fine. Now, I wanted to do it with reshape2::melt and it throws an error. Why is reshape2::melt behaving differently? Is there another comparatively fast solution for this problem, e.g., in the tidyverse?
a <- spatstat.geom::im(matrix(rep(1:3,3), ncol = 3))
tmp <- list(a = a,
b = a)
reshape::melt(tmp)
The output is:
# value.x value.y value.value value.optional L1
# 1 1 1 1 TRUE a
# 2 1 2 2 TRUE a
# 3 1 3 3 TRUE a
# 4 2 1 1 TRUE a
# 5 2 2 2 TRUE a
# 6 2 3 3 TRUE a
# 7 3 1 1 TRUE a
# 8 3 2 2 TRUE a
# 9 3 3 3 TRUE a
# 10 1 1 1 TRUE b
# 11 1 2 2 TRUE b
# 12 1 3 3 TRUE b
# 13 2 1 1 TRUE b
# 14 2 2 2 TRUE b
# 15 2 3 3 TRUE b
# 16 3 1 1 TRUE b
# 17 3 2 2 TRUE b
# 18 3 3 3 TRUE b
reshape2::melt(tmp)
This throws the following error:
Error in vector(type, length): vector: cannot generate a vector of mode 'NULL'.