Skip to content
Prev 388458 / 398513 Next

Some difficulties to use the apply command on an array

apply _always_ returns a matrix of vector results. That is, the result of each call to FUN may be a matrix, but a matrix is merely a vector with dimensions that are in this case ignored. So restore the dimensions on the result:

array(apply(x, 1, FUN = function(x) diag( svd(x)$d )), dim=c(3,3,5))
On July 5, 2021 8:15:16 AM PDT, Eric Berger <ericjberger at gmail.com> wrote: