1

我有一组核心温度值。在几个小时的持续时间内,我每 10 秒收集一个温度值。我试图在 6 个温度值内找到温度的最高增量(Tslope)。我尝试了滚动平均的方法,但我什至没有接近解决方案。数据集如下所示:

R001 <- R001_G2_Q3_T

Test Subject      Datum                Zeit Temperatur Timepoint
1     G2    R001 2018-10-27 1899-12-31 16:51:45       38.4        Q3
2     G2    R001 2018-10-27 1899-12-31 16:51:55       38.4        Q3
3     G2    R001 2018-10-27 1899-12-31 16:52:05       38.4        Q3
4     G2    R001 2018-10-27 1899-12-31 16:52:15       38.4        Q3
5     G2    R001 2018-10-27 1899-12-31 16:52:25       38.4        Q3
6     G2    R001 2018-10-27 1899-12-31 16:52:35       38.3        Q3
7     G2    R001 2018-10-27 1899-12-31 16:52:45       38.4        Q3
8     G2    R001 2018-10-27 1899-12-31 16:52:55       38.5        Q3
9     G2    R001 2018-10-27 1899-12-31 16:53:06       38.3        Q3
10    G2    R001 2018-10-27 1899-12-31 16:53:16       38.4        Q3
11    G2    R001 2018-10-27 1899-12-31 16:53:26       38.4        Q3
12    G2    R001 2018-10-27 1899-12-31 16:53:36       38.4        Q3
13    G2    R001 2018-10-27 1899-12-31 16:53:46       38.4        Q3
14    G2    R001 2018-10-27 1899-12-31 16:53:56       38.4        Q3
15    G2    R001 2018-10-27 1899-12-31 16:54:06       38.3        Q3
16    G2    R001 2018-10-27 1899-12-31 16:54:16       38.3        Q3
17    G2    R001 2018-10-27 1899-12-31 16:54:26       38.3        Q3
18    G2    R001 2018-10-27 1899-12-31 16:54:36       38.4        Q3
19    G2    R001 2018-10-27 1899-12-31 16:54:47       38.4        Q3
20    G2    R001 2018-10-27 1899-12-31 16:54:57       38.3        Q3
21    G2    R001 2018-10-27 1899-12-31 16:55:07       38.4        Q3
22    G2    R001 2018-10-27 1899-12-31 16:55:17       38.4        Q3
23    G2    R001 2018-10-27 1899-12-31 16:55:27       38.4        Q3
24    G2    R001 2018-10-27 1899-12-31 16:55:37       38.4        Q3
25    G2    R001 2018-10-27 1899-12-31 16:55:47       38.5        Q3
26    G2    R001 2018-10-27 1899-12-31 16:55:57       38.4        Q3
27    G2    R001 2018-10-27 1899-12-31 16:56:07       38.4        Q3
28    G2    R001 2018-10-27 1899-12-31 16:56:17       38.4        Q3
29    G2    R001 2018-10-27 1899-12-31 16:56:28       38.5        Q3
30    G2    R001 2018-10-27 1899-12-31 16:56:38       38.4        Q3
31    G2    R001 2018-10-27 1899-12-31 16:56:48       38.4        Q3
32    G2    R001 2018-10-27 1899-12-31 16:56:58       38.5        Q3
33    G2    R001 2018-10-27 1899-12-31 16:57:08       38.5        Q3
[...]

我期望的是,我可以说例如:“在 16:55 和 16:56 之间,核心温度升高了 0.3°C”

当我向您另外展示一张图片时,也许更容易理解我的问题: 在此处输入图像描述

我喜欢找到的是 Tslope:Tslope 将在一分钟内迭代计算,包括 6 个连续的测量时间点。当然,我的数据集包含更多的值,会有类似图像中的曲线。

如果有人能在这种情况下帮助我,那就太好了。谢谢你的帮助。

4

2 回答 2

1

这是使用data.table.

样本数据

library( data.table )

DT <- fread("ID Test Subject      Datum                Zeit Temperatur Timepoint
1     G2    R001 2018-10-27 '1899-12-31 16:51:45'       38.4        Q3
2     G2    R001 2018-10-27 '1899-12-31 16:51:55'       38.4        Q3
3     G2    R001 2018-10-27 '1899-12-31 16:52:05'       38.4        Q3
4     G2    R001 2018-10-27 '1899-12-31 16:52:15'       38.4        Q3
5     G2    R001 2018-10-27 '1899-12-31 16:52:25'       38.4        Q3
6     G2    R001 2018-10-27 '1899-12-31 16:52:35'       38.3        Q3
7     G2    R001 2018-10-27 '1899-12-31 16:52:45'       38.4        Q3
8     G2    R001 2018-10-27 '1899-12-31 16:52:55'       38.5        Q3
9     G2    R001 2018-10-27 '1899-12-31 16:53:06'       38.3        Q3
10    G2    R001 2018-10-27 '1899-12-31 16:53:16'       38.4        Q3
11    G2    R001 2018-10-27 '1899-12-31 16:53:26'       38.4        Q3
12    G2    R001 2018-10-27 '1899-12-31 16:53:36'       38.4        Q3
13    G2    R001 2018-10-27 '1899-12-31 16:53:46'       38.4        Q3
14    G2    R001 2018-10-27 '1899-12-31 16:53:56'       38.4        Q3
15    G2    R001 2018-10-27 '1899-12-31 16:54:06'       38.3        Q3
16    G2    R001 2018-10-27 '1899-12-31 16:54:16'       38.3        Q3
17    G2    R001 2018-10-27 '1899-12-31 16:54:26'       38.3        Q3
18    G2    R001 2018-10-27 '1899-12-31 16:54:36'       38.4        Q3
19    G2    R001 2018-10-27 '1899-12-31 16:54:47'       38.4        Q3
20    G2    R001 2018-10-27 '1899-12-31 16:54:57'       38.3        Q3
21    G2    R001 2018-10-27 '1899-12-31 16:55:07'       38.4        Q3
22    G2    R001 2018-10-27 '1899-12-31 16:55:17'       38.4        Q3
23    G2    R001 2018-10-27 '1899-12-31 16:55:27'       38.4        Q3
24    G2    R001 2018-10-27 '1899-12-31 16:55:37'       38.4        Q3
25    G2    R001 2018-10-27 '1899-12-31 16:55:47'       38.5        Q3
26    G2    R001 2018-10-27 '1899-12-31 16:55:57'       38.4        Q3
27    G2    R001 2018-10-27 '1899-12-31 16:56:07'       38.4        Q3
28    G2    R001 2018-10-27 '1899-12-31 16:56:17'       38.4        Q3
29    G2    R001 2018-10-27 '1899-12-31 16:56:28'       38.5        Q3
30    G2    R001 2018-10-27 '1899-12-31 16:56:38'       38.4        Q3
31    G2    R001 2018-10-27 '1899-12-31 16:56:48'       38.4        Q3
32    G2    R001 2018-10-27 '1899-12-31 16:56:58'       38.5        Q3
33    G2    R001 2018-10-27 '1899-12-31 16:57:08'       38.5        Q3", quote = "'")

代码

#extract time from Zeit
DT[, Zeit := gsub(".* (.*$)", "\\1", Zeit)]
#create posixct timestamp
DT[, timestamp := as.POSIXct( paste0( Datum, "T", Zeit ), format = "%Y-%m-%dT%H:%M:%S", tz = "GMT" ) ]
#create a minute-colum to summarise on
DT[, time_summ := format( timestamp, "%Y-%m-%dT%H:%M" ) ]
#calculate delta
DT[, deltaT := Temperatur - shift( Temperatur, type = "lag" )]
#summarise, het the maximum deltaT by minute
DT[, .(max_deltaT = max( deltaT, na.rm = TRUE ) ), by = .(period = time_summ ) ]

输出

#              period max_deltaT
# 1: 2018-10-27T16:51        0.0
# 2: 2018-10-27T16:52        0.1
# 3: 2018-10-27T16:53        0.1
# 4: 2018-10-27T16:54        0.1
# 5: 2018-10-27T16:55        0.1
# 6: 2018-10-27T16:56        0.1
# 7: 2018-10-27T16:57        0.0
于 2020-02-12T13:38:42.237 回答
1

我猜这就是你要找的:

DT[, maxTslope_last6 := frollapply(Temperatur, n = 6, function(x) max(diff(x)))]

> DT
    ID Test Subject      Datum                Zeit Temperatur Timepoint maxTslope_last6
 1:  1   G2    R001 2018-10-27 1899-12-31 16:51:45       38.4        Q3              NA
 2:  2   G2    R001 2018-10-27 1899-12-31 16:51:55       38.4        Q3              NA
 3:  3   G2    R001 2018-10-27 1899-12-31 16:52:05       38.4        Q3              NA
 4:  4   G2    R001 2018-10-27 1899-12-31 16:52:15       38.4        Q3              NA
 5:  5   G2    R001 2018-10-27 1899-12-31 16:52:25       38.4        Q3              NA
 6:  6   G2    R001 2018-10-27 1899-12-31 16:52:35       38.3        Q3             0.0
 7:  7   G2    R001 2018-10-27 1899-12-31 16:52:45       38.4        Q3             0.1
 8:  8   G2    R001 2018-10-27 1899-12-31 16:52:55       38.5        Q3             0.1
 9:  9   G2    R001 2018-10-27 1899-12-31 16:53:06       38.3        Q3             0.1
10: 10   G2    R001 2018-10-27 1899-12-31 16:53:16       38.4        Q3             0.1
11: 11   G2    R001 2018-10-27 1899-12-31 16:53:26       38.4        Q3             0.1
12: 12   G2    R001 2018-10-27 1899-12-31 16:53:36       38.4        Q3             0.1
13: 13   G2    R001 2018-10-27 1899-12-31 16:53:46       38.4        Q3             0.1
14: 14   G2    R001 2018-10-27 1899-12-31 16:53:56       38.4        Q3             0.1
15: 15   G2    R001 2018-10-27 1899-12-31 16:54:06       38.3        Q3             0.0
16: 16   G2    R001 2018-10-27 1899-12-31 16:54:16       38.3        Q3             0.0
17: 17   G2    R001 2018-10-27 1899-12-31 16:54:26       38.3        Q3             0.0
18: 18   G2    R001 2018-10-27 1899-12-31 16:54:36       38.4        Q3             0.1
19: 19   G2    R001 2018-10-27 1899-12-31 16:54:47       38.4        Q3             0.1
20: 20   G2    R001 2018-10-27 1899-12-31 16:54:57       38.3        Q3             0.1
21: 21   G2    R001 2018-10-27 1899-12-31 16:55:07       38.4        Q3             0.1
22: 22   G2    R001 2018-10-27 1899-12-31 16:55:17       38.4        Q3             0.1
23: 23   G2    R001 2018-10-27 1899-12-31 16:55:27       38.4        Q3             0.1
24: 24   G2    R001 2018-10-27 1899-12-31 16:55:37       38.4        Q3             0.1
25: 25   G2    R001 2018-10-27 1899-12-31 16:55:47       38.5        Q3             0.1
26: 26   G2    R001 2018-10-27 1899-12-31 16:55:57       38.4        Q3             0.1
27: 27   G2    R001 2018-10-27 1899-12-31 16:56:07       38.4        Q3             0.1
28: 28   G2    R001 2018-10-27 1899-12-31 16:56:17       38.4        Q3             0.1
29: 29   G2    R001 2018-10-27 1899-12-31 16:56:28       38.5        Q3             0.1
30: 30   G2    R001 2018-10-27 1899-12-31 16:56:38       38.4        Q3             0.1
31: 31   G2    R001 2018-10-27 1899-12-31 16:56:48       38.4        Q3             0.1
32: 32   G2    R001 2018-10-27 1899-12-31 16:56:58       38.5        Q3             0.1
33: 33   G2    R001 2018-10-27 1899-12-31 16:57:08       38.5        Q3             0.1
    ID Test Subject      Datum                Zeit Temperatur Timepoint maxTslope_last6
于 2020-02-13T13:40:02.427 回答