I want to replace the diagonal elements of a matrix in the middle of a piping process but can't figure out a way to do this. I know I can replace the diagonal elements this using diag() function, but I just don't know how to use diag() function inside a piping process. Sample data is given below and I want the following steps put together in a piping process. Thanks in advance.
aa <- matrix(1:25, nrow =5)
diag(aa) <- NA