1

My image data is stored in a list. For every pixel (626257) of my image I have a vector containing all the values corresponding to the different wavelengths (44 wavelengths). Now I would like to carry out a principal component analysis (PCA). Unfortunately, I am not able to convert my listed data into the desired form. Here is the code to generate a dummy data set.

test = replicate(626257, rnorm(44, 3, 1),simplify = FALSE)

When I now try to carry out the PCA then the following error message pops up.

pca = prcomp(test, scale = F)
Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric

How can I convert my list into a suitable datatype?

stefan
  • 19
  • 5
  • If this is the format of your dataset, couldn't you simply use `as.data.frame` or `data.table::as.data.table`, and use `prcomp` from this point? – Oliver Aug 11 '19 at 13:08
  • When I apply: **test = as.data.frame(test)**, then the structure of my data changes. **View(test)** results in 10 columns with 44 entities, respectively. But I would expect 626257 columns with each 44 entities. – stefan Aug 11 '19 at 17:32

1 Answers1

0

We could change the simplify = TRUE in replicate and it should work

test <- replicate(10, rnorm(44, 3, 1),simplify = FALSE)
pca = prcomp(test, scale = FALSE)
akrun
  • 874,273
  • 37
  • 540
  • 662