If I have a list of matrices with same dimensions, how can I get each element of list of matrices in R? For example, I have 4 matrices:
> a
[,1] [,2] [,3]
[1,] -0.8761453 0.2821336 -0.8541406
[2,] -0.9649200 1.7734091 -1.2058440
[3,] -0.4250063 -0.8197162 -1.3997540
> b
[,1] [,2] [,3]
[1,] -1.2096577 -0.5440074 0.6102016
[2,] -0.1299645 -0.8943189 -1.8042720
[3,] 1.0111488 0.2547343 0.2395172
> c
[,1] [,2] [,3]
[1,] 0.2853833 -0.2716714 0.2330467
[2,] -0.7963095 -1.2120779 0.6909755
[3,] 0.3479346 0.1803124 -0.7400176
> d
[,1] [,2] [,3]
[1,] -1.048740842 -1.0492152 -0.6889409
[2,] -0.004154795 -0.6167335 -0.8028550
[3,] -1.111915258 -2.1586534 -0.1448612
The result I want is if I want the 2nd least minimum of each element.
> res
[,1] [,2] [,3]
[1,] -1.0487408 -0.5440074 -0.6889409
[2,] -0.7963095 -0.8943189 -1.2058440
[3,] -0.4250063 -0.8197162 -0.7400176
If we need the second minimum value, create an
arrayby concatenating thematrixes together, specify the dimensions and useapplywith the requiredMARGIN,sortthe elements from smallest to largest and get the second elementNOTE: Based on the OP's post, it looks like 'a', 'b', 'c', 'd' are separate
matrixobjects in the global environment