gpt4 book ai didi

r - 使用R查找最大值之前的行

转载 作者:行者123 更新时间:2023-12-02 01:39:51 25 4
gpt4 key购买 nike

我有兴趣在 R 中找到最大值之前的行。数据框如下所示:

    timeround   n
1 01:00 11
2 02:00 6
3 03:00 4
4 04:00 4
5 05:00 7
6 06:00 22
7 07:00 63
8 08:00 142
9 09:00 155
10 10:00 220
11 11:00 143
12 12:00 98
13 13:00 111
14 14:00 115
15 15:00 129
16 16:00 128
17 17:00 102
18 18:00 90
19 19:00 108
20 20:00 92
21 21:00 90
22 22:00 102
23 23:00 44
24 24:00 20

目前我能够显示最大值,使用:

with(tweetcount, timeround[n== max(n)])

给我值“10:00”

如何计算 R 以给出最大值之前的值 - 在本例中为“9:00”?

最佳答案

你可以使用which

with(tweetcount, timeround[which(n== max(n))-1])

如果只有一个max

 tweetcount$timeround[which.max(tweetcount$n)-1]

关于r - 使用R查找最大值之前的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29036886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com