[問題] 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