Reputation: 25
I generated 1000 2x2 random matrices with:
M=lapply(1:1000, function(z) matrix(runif(1000,min=-10,max=10), ncol = 2, nrow = 2)) eig=lapply(M, eigen)
Thank you so much in advance!
Upvotes: 1
Views: 690
Reputation: 887941
We can extract the 'values' from a list using [[
by looping over the elements of list
with sapply
and this is done with base R
out <- c(sapply(eig, `[[`, "values"))
plot(out)
Or with pluck
library(tidyverse)
map(eig, pluck, "values") %>%
unlist
Upvotes: 2
Reputation: 3994
If you want a base R solution you can turn this into a
mats <- matrix(unlist(lapply(e, function(x) lapply(x, unlist)$values)), ncol = 2, byrow = T)
Upvotes: 0