【发布时间】:2013-06-03 14:42:56
【问题描述】:
我在使用 R 编程时遇到问题。从矩阵中,我怎样才能找到排除对角线的每一行的中位数?
例如:矩阵 4x4
0 1 2 3
1 0 1 2
2 1 0 1
3 2 1 0
我想找出每行不包括对角线的中位数(在这个例子中,diag=0)
我试过了:
diag(A) <- NA
mean(A, na.rm = TRUE) # doesn't work
apply(A, 1, median) # it works but the calculation including the diagonal.
【问题讨论】: