(24まで):
呼び出す
which
は(ここでは一つだけ)の行と列を与えるとき
arr.ind=TRUE
を使用して
Mobile Juneau Phoenix Little Rock Los Angeles
1 9.161109 6.561874 7.900787 3.863214 7.2799115
2 5.597790 3.267891 3.895087 7.589563 0.5756907
3 6.279322 3.578783 5.273761 8.076495 6.2456569
4 3.895283 4.321506 2.665034 2.755444 9.8913468
5 5.889698 5.690749 8.879107 8.233134 3.2684326
6 7.811671 2.033278 1.528914 7.719961 1.3486213
:
> which(df==max(df),arr.ind=TRUE)
row col
[1,] 14 5
次に、rownamesを使用して都市名と時間を取得できるはずです(詳細は?which
を参照)。
テストデータ:
df <- structure(list(Mobile = c(9.16110935388133, 5.59779000002891,
6.27932160394266, 3.89528321102262, 5.88969846023247, 7.81167097389698,
1.83368496363983, 4.47858408326283, 5.93715427909046, 3.50760932080448,
9.44435691693798, 6.31296712905169, 5.32727922545746, 7.65801254892722,
8.5059278132394, 4.28985294653103, 2.05249830847606, 7.6365390396677,
9.77846014779061, 8.94446840044111, 0.083497145678848, 7.10133319022134,
0.554085657931864, 3.60153668094426), Juneau = c(6.56187414424494,
3.26789108337834, 3.57878275448456, 4.32150553911924, 5.69074853556231,
2.033277512528, 7.18786624493077, 6.14864403847605, 8.68574564578012,
1.30817822180688, 1.01500122342259, 8.8916674698703, 5.60441857203841,
8.86488395975903, 6.64872422581539, 0.683707664720714, 0.72935079690069,
6.96065725525841, 1.50260855443776, 9.30632123956457, 8.09938014484942,
3.17607591627166, 1.66992667596787, 6.5417457325384), Phoenix = c(7.90078683523461,
3.89508724678308, 5.27376119513065, 2.66503410181031, 8.87910738587379,
1.52891436824575, 1.83640674687922, 7.62884735595435, 1.86433888971806,
6.2539599230513, 0.442896636668593, 8.08971904451028, 3.22157387156039,
1.07892997562885, 5.32610179157928, 5.71723570115864, 8.49908272270113,
9.22176177380607, 5.49865348497406, 2.0716791623272, 2.75534275220707,
9.54129027202725, 0.547004980035126, 0.0254918588325381), `Little Rock` = c(3.86321445228532,
7.58956262841821, 8.0764949019067, 2.75544387986884, 8.23313429951668,
7.71996134659275, 6.78180204005912, 2.48242149595171, 5.22057399619371,
8.16672697663307, 2.18510434962809, 8.52984978584573, 4.81410115258768,
9.26382135832682, 5.73062423849478, 4.68517286004499, 4.98139521572739,
2.03285798197612, 1.81552906520665, 1.28075355896726, 7.3631735984236,
9.16532466653734, 3.6388257634826, 6.7194988601841), `Los Angeles` = c(7.27991148363799,
0.575690739788115, 6.24565688893199, 9.89134680945426, 3.26843255432323,
1.34862127713859, 0.358565023634583, 9.37912961700931, 1.25442329328507,
1.73299844376743, 9.95316742919385, 7.42675306508318, 6.60283848410472,
9.98386316467077, 5.81940121715888, 2.53246366977692, 4.47731937048957,
0.9123918088153, 7.94102079933509, 7.45049795368686, 1.02275986224413,
2.63348019681871, 1.82409069268033, 7.71245903801173)), row.names = c(NA,
-24L), class = "data.frame", .Names = c("Mobile", "Juneau", "Phoenix",
"Little Rock", "Los Angeles"))
あなたはあなたのdata.frameの例を投稿してもらえますか?どうも! :) – Ale
各時間(行)の最高温度で都市(列)を検索する場合は、特定の問題に対して 'max.col'関数が機能するかもしれません。 – lmo