看板 R_Language 關於我們 聯絡資訊
- 問題: 當你想要問問題時,請使用這個類別 [問題類型]: 程式諮詢(我想用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 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.76.246.58 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1465959862.A.F49.html
celestialgod: 最大值:mat[which.max(mat)] 06/15 11:08
celestialgod: colnames(mat)[arrayInd(which.max(mat), dim(mat)) 06/15 11:09
celestialgod: [2]] 06/15 11:09
celestialgod: 上面那行是抓column name 06/15 11:10
celestialgod: http://pastebin.com/VNsSfBPp 06/15 11:11
感謝C大支援!!! 順利拿到資訊了~ ※ 編輯: aee36900 (211.76.246.58), 06/15/2016 11:27:29 ※ 編輯: aee36900 (211.76.246.58), 06/15/2016 11:28:20