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:9, nrow=3) #result: upperRowSums(m) ## [1] 12 13 9 lowerRowSums(m) ## [1] 1 7 18
これは単純なループで実行できることはわかっていますが、これはfor避けたいと思います。私は純粋なR解決策を探しています。
for
R
あちらへ:
rowSums(m * upper.tri(m, diag=TRUE)) #[1] 12 13 9