对于R中的对角矩阵,将0替换为1,反之亦然

Shr*_*uti 4 r

任何人都可以告诉我如何用1代替0,反之亦然代替R中的对角矩阵.

Joh*_*ohn 14

如果您的矩阵是mat并且您想要将所有1都翻转为0 ...

mat <- 1-mat
Run Code Online (Sandbox Code Playgroud)