[问题] matrix找出max value与column name

楼主: aee36900 (持久战!!)   2016-06-15 11:04:18
- 问题: 当你想要问问题时,请使用这个类别
[问题类型]:
程式咨询(我想用R 做某件事情,但是我不知道要怎么用R 写出来)
[软件熟悉度]:
请把以下不需要的部份删除
新手(没写过程式,R 是我的第一次)
[问题叙述]:
手上有一个matrix data如下
lag0 lag1 lag2 lag3 lag4 lag5 lag6
8 1.009114 1.007150 1.004775 1.004175 1.003529 1.002235 1.005105
10 1.011406 1.008945 1.005972 1.005221 1.004413 1.002794 1.006385
12 1.013703 1.010744 1.007171 1.006269 1.005298 1.003354 1.007667
14 1.016005 1.012546 1.008371 1.007317 1.006183 1.003914 1.008951
16 1.018312 1.014351 1.009573 1.008367 1.007070 1.004474 1.010236
想要找出最大值且在哪一个字段
目前知道可以透过
which(mat == max(mat), arr.ind = TRUE)
找到位置
row col
16 5 1
请问如何可以进一步或是可以直接
得到lag0 以及 1.018312 这两个值呢?
谢谢
[关键字]:
matrix max column name
作者: celestialgod (天)   2016-06-15 11:08:00
最大值:mat[which.max(mat)]colnames(mat)[arrayInd(which.max(mat), dim(mat))[2]]上面那行是抓column namehttp://pastebin.com/VNsSfBPp

Links booklink

Contact Us: admin [ a t ] ucptt.com