I tried the below code to get the squares of the terms in the matrix format.

x<-matrix(1:9,3)

sapply(x,function(y) y^2)

This returns a single vector of squares

sapply(x,function(y) y^2,simplify = F)

This returns a list where every element is a vector.

I want the original 3x3 matrix. I understand there are easier ways, but I’m trying to understand the apply functions.