简体   繁体   English

在R中-通过查找不同值的最大值的规则从列中提取值

[英]In R - Extracting a value from a column, by the rule of finding the highest value of a different value

i have a 3 x 8 Data Frame, and i need to extract the day (column 3) that matches the highest value (column 1) from the Data Frame. 我有一个3 x 8数据框,我需要从数据框中提取与最高值(第1列)相匹配的日期(第3列)。

For example, 例如,

1    0.931 2015-03-20    Friday
2   -0.105 2015-03-23    Monday
3   -0.470 2015-03-24   Tuesday
4   -0.149 2015-03-25 Wednesday

the highest value is 0.931, so i need to extract the value Friday. 最高值为0.931,所以我需要在星期五提取值。

Thanks. 谢谢。

Say, your dataframe ( df ) has the values in column named V1 then you can find the index of the maximum value in this column with which.max(df$V1) . 假设您的数据帧( df )在名为V1列中具有值,那么您可以使用which.max(df$V1)在此列中找到最大值的索引。 You say you want the corresponding day for this value, say the days are in column named V2 then your day is df$V2[which.max(df$V1)] . 您说您想要该值的对应天,例如,天在名为V2列中,那么您的天就是df$V2[which.max(df$V1)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM