Skip to content

using eigen function in MAP and purr

1 message · John Fox

#
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: