So I have a large list of matrices and I want to be able to take them one by one and unlist them into their normal 2D individual matrices. So let's say I have a list of matrices examplelist. I obtained the list with this code:
examplelist <- lapply(listofimages, readImage)
And here is one sample image 512x512 .tif which would be one of the matrices in the list of matrices :
The list looks like this:
I want to take out one matrix at a time as a 2D 512x512 matrix but when I try to trim out the other data manually its still a list element (single quotes to make the index not referenced):
a <- as.matrix(examplelist['1'])
b <- a[,]
And when I do this it flattens into a 1D vector:
b <- as.numeric(unlist(examplelist['1']))
Which is 262144 x 1 instead of 512 x 512.
Ive tried converting it to a data table, data frame, and a few other things and then when I get to trying to make it numeric:
as.numeric(b)
I get this error:
Using dput, it lists this as the error:
Is there an easy way to unlist a square matrix from a list of matrices and get it in its original 512 x 512 form rather than a 1D vector (as seen above)?
I tried trimming dimensions (seen above) to get rid of some of the other info but it threw an error. I also tried accessing just the data attributes using '@' and '$' but that didn't work either.
If I try this:
b <- as.data.table(examplelist['1'])
It just gives me another 262144 x 1 1D vector instead of the desired 2D matrix.
This solution and this, don't work because I dont want a 1D vector or to only convert elements (I want the whole matrix) as numeric elements.