Search code examples
rmatrixploteigenvalue

How to plot eigenvalues on R?


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!


Solution

  • 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