【发布时间】:2021-05-31 15:28:58
【问题描述】:
在我的数据框 CORtrial 我有两列,rDate 采用 POSixct 格式,从 2015-07-27 17:45:00 到 2017-08-31 16:55:00 和 REFN630 采用numeric 格式。 REFN630 的值记录在 rDate 中,时间间隔为 5,每 5 分钟。
这就是我的数据框的结构:
dput(head(CORtrial,10))
structure(list(rDate = structure(c(1438019100, 1438019400, 1438019700,
1438020000, 1438020300, 1438020600, 1438020900, 1438021200, 1438021500,
1438021800), class = c("POSIXct", "POSIXt"), tzone = ""), REFN630 = c(0.0111940298507463,
0.0671936758893281, 0.0143198090692124, 0.0087719298245614, 0.00936768149882904,
0.00985221674876847, 0.00775193798449612, 0.00815217391304348,
0.00859598853868195, 0.00911854103343465)), row.names = c(NA,
-10L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000024f693c1ef0>)
我想知道特定日期和时间间隔之间的max值,例如我想知道rDate之间的REFN630的MAXIMUM值@ 987654327@ 和2015-10-23 11:40:00。我该怎么做?
2) 全程取最大值后:
df %>%
filter(ymd_hms(rDate) %within%
interval(ymd_hms("2015-07-27 22:25:00"), ymd_hms("2015-07-27 22:50:00"))) %>%
slice_max(order_by = REFN630)
rDate REFN630
1: 2015-07-27 22:25:00 0.01431981
向数据框中添加了更多列,结构如下:
dput(head(COR_trial,10))
structure(list(rDate = structure(c(1438015500, 1438015800, 1438016100,
1438016400, 1438016700, 1438017000, 1438017300, 1438017600, 1438017900,
1438018200), class = c("POSIXct", "POSIXt"), tzone = ""), REFN532 = c(0.0127971,
0.1348315, 0.0215983, 0.0143443, 0.0150862, 0.0158014, 0.0167866,
0.0152284, 0.0162162, 0.0172911), REFN570 = c(0.0172414, 0.1515748,
0.0171306, 0.0149573, 0.0157303, 0.0142518, 0.0150376, 0.016,
0.0142045, 0.0151976), REFN630 = c(0.011194, 0.0671937, 0.0143198,
0.0087719, 0.0093677, 0.0098522, 0.0077519, 0.0081522, 0.008596,
0.0091185), REFN800 = c(0.0169082, 0.1030928, 0.0560472, 0.0569801,
0.0574018, 0.0573248, 0.0531561, 0.0520833, 0.0510949, 0.0498084
)), row.names = c(NA, 10L), class = "data.frame")
现在,当我使用代码获取 REFN630 的最大值时,我得到的是:
COR_trial %>%
filter(ymd_hms(rDate) %within%
interval(ymd_hms("2015-07-27 16:00:00"), ymd_hms("2015-07-27 18:00:00"))) %>%
slice_max(order_by = REFN630)
rDate REFN532 REFN570 REFN630 REFN800
1 2015-07-27 17:50:00 0.1348315 0.1515748 0.0671937 0.1030928
期望的输出是:
rDate REFN630
1 2015-07-27 17:50:00 0.0671937
我该怎么做? 提前致谢。
【问题讨论】: