Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は対称行列 (例: M <- matrix(1:4, ncol = 2)) を持っており、オフの対角要素を に設定したいと考えてい0ます。より賢い方法はありdiag(diag(M), ncol = ncol(M))ますか?
M <- matrix(1:4, ncol = 2)
0
diag(diag(M), ncol = ncol(M))
注:diagの使用はサポートされておらず、などdiag(M, ncol = ncol(M))のオプションもありません。diag(M, as.matrix = TRUE)
diag
diag(M, ncol = ncol(M))
diag(M, as.matrix = TRUE)