I have a function that returns 300 arrays as follows:
, , 38 [,1] [,2] [,3] [,4] [,5] [1,] 1.0000000 1.000000 1.000000 1.000000 1 [2,] 1.4457207 1.000000 1.000000 1.000000 1 [3,] 1.1491685 1.152171 1.000000 1.000000 1 [4,] 0.9009709 0.600254 1.444501 1.000000 1 [5,] 1.0620356 1.769513 1.147224 2.505219 1 , , 39 [,1] [,2] [,3] [,4] [,5] [1,] 1.0000000 1.0000000 1.0000000 1.000000 1 [2,] 1.0693369 1.0000000 1.0000000 1.000000 1 [3,] 1.8235562 1.6199451 1.0000000 1.000000 1 [4,] 0.6631731 0.9665938 0.2569683 1.000000 1 [5,] 0.7608913 2.3203717 0.7305705 4.549893 1 , , 40 [,1] [,2] [,3] [,4] [,5] [1,] 1.000000 1.0000000 1.000000 1.000000 1 [2,] 1.003870 1.0000000 1.000000 1.000000 1 [3,] 1.206578 0.8969491 1.000000 1.000000 1 [4,] 1.205347 1.2673170 1.345472 1.000000 1 [5,] 2.741506 2.0376783 1.151699 2.787262 1
I would like to convert all the top ones (including the diagonal) to 0 .
lapply(x,function(x) x[,,][upper.tri(x[,,],diag = T)] <- 0)
but does not work. Any help please?