开发者

How to sum leading diagonal of table in R

I have 开发者_C百科a table created using the table() command in R:

   y
x    0  1  2  3  4  5  6  7  8  9
  0 23  0  0  0  0  1  0  0  0  0
  1  0 23  1  0  1  0  1  2  0  2
  2  1  1 28  0  0  0  1  0  2  2
  3  0  1  0 24  0  1  0  0  0  1
  4  1  1  0  0 34  0  3  0  0  0
  5  0  0  0  0  0 33  0  0  0  0
  6  0  0  0  0  0  2 32  0  0  0
  7  0  1  0  1  0  0  0 36  0  1
  8  1  1  1  1  0  0  0  1 20  1
  9  1  3  0  1  0  1  0  1  0 24

This table shows the results of a classification, and I want to sum the leading diagonal of it (the diagonal with the large numbers - like 23, 23, 28 etc). Is there a sensible/easy way to do this in R?


How about sum(diag(tbl)), where tbl is your table?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜