1
我在R編程時遇到了問題。從矩陣中,我怎樣才能找到每行的中位數排除對角線?在R中找到排除對角線的中位數
例:矩陣的4x4
0 1 2 3
1 0 1 2
2 1 0 1
3 2 1 0
我想找到的每一行除對角線的中位數(在此前,該診斷= 0)
我已經試過:
diag(A) <- NA
mean(A, na.rm = TRUE) # doesn't work
apply(A, 1, median) # it works but the calculation including the diagonal.