Skip to content
Prev 387654 / 398502 Next

using eigen function in MAP and purr

Dear V. K. Chetty,

Perhaps I'm missing something but why wouldn't you just use a list of 
matrices, as in the following?

---------- snip ---------

 > set.seed(123) # for reproducibility

 > (Matrices <- lapply(1:3, function(i) matrix(sample(1:50, 4), 2, 2)))

[[1]]
      [,1] [,2]
[1,]   31   14
[2,]   15    3

[[2]]
      [,1] [,2]
[1,]   42   37
[2,]   43   14

[[3]]
      [,1] [,2]
[1,]   25   27
[2,]   26    5

 > (Eigenvalues <- lapply(Matrices, function(x) eigen(x, 
only.values=TRUE)$values))

[[1]]
[1] 37.149442 -3.149442

[[2]]
[1]  70.27292 -14.27292

[[3]]
[1]  43.3196 -13.3196

---------- snip ---------

I hope this helps,
  John

John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/
On 2021-03-29 5:28 p.m., Veerappa Chetty wrote:
Message-ID: <3247fcf1-1b1b-fb60-3a97-4c7ef4bc5b76@mcmaster.ca>
In-Reply-To: <8600_1617053434_12TLUXK1030775_CAFpsATa-z3j-iLq+M9xozToifm_Qc_--S1j_pvSaZzPfFWorsA@mail.gmail.com>