如何取具有特定时间格式的时间序列数据的平均值
How to take average of time series data with specific time format
我有一个形式为 mm:ss.s 的时间序列。我想要做的是每 1 分钟 取 a 到 c 列数据的平均值。重点是59:09.9后时间会重置为00:00.0
我不知道应该如何导入这种类型的时间值,所以为了保持数据不变,我以字符形式导入时间。
数据提供如下:
structure(list(DATETIME = c("00:00.5", "00:01.1", "00:01.7",
"00:02.2", "00:02.8", "00:03.4", "00:03.9", "00:04.5", "00:05.0",
"00:05.6", "00:06.2", "00:06.7", "00:07.3", "00:07.9", "00:08.4",
"00:09.0", "00:09.5", "00:10.1", "00:10.7", "00:11.2", "00:11.8",
"00:12.4", "00:12.9", "00:13.5", "00:14.0", "00:14.6", "00:15.2",
"00:15.7", "00:16.3", "00:16.9", "00:17.4", "00:18.0", "00:18.5",
"00:19.1", "00:19.7", "00:20.2", "00:20.8", "00:21.4", "00:21.9",
"00:22.5", "00:23.0", "00:23.6", "00:24.2", "00:24.7", "00:25.3",
"00:25.9", "00:26.4", "00:27.0", "00:27.5", "00:28.1", "00:28.7",
"00:29.2", "00:29.8", "00:30.4", "00:30.9", "00:31.5", "00:32.0",
"00:32.6", "00:33.2", "00:33.7", "00:34.3", "00:34.9", "00:35.4",
"00:36.0", "00:36.5", "00:37.1", "00:37.7", "00:38.2", "00:38.8",
"00:39.4", "00:39.9", "00:40.5", "00:41.1", "00:41.6", "00:42.2",
"00:42.7", "00:43.3", "00:43.9", "00:44.4", "00:45.0", "00:45.5",
"00:46.1", "00:46.7", "00:47.2", "00:47.8", "00:48.4", "00:48.9",
"00:49.5", "00:50.0", "00:50.6", "00:51.2", "00:51.7", "00:52.3",
"00:52.9", "00:53.4", "00:54.0", "00:54.5", "00:55.1", "00:55.7",
"00:56.2", "00:56.8", "00:57.4", "00:57.9", "00:58.5", "00:59.0",
"00:59.6", "01:00.2", "01:00.7", "01:01.3", "01:01.9", "01:02.4",
"01:03.0", "01:03.5", "01:04.1", "01:04.7", "01:05.2", "01:05.8",
"01:06.4", "01:06.9", "01:07.5", "01:08.0", "01:08.6", "01:09.2",
"01:09.7", "01:10.3", "01:10.9", "01:11.4", "01:12.0", "01:12.5",
"01:13.1", "01:13.7", "01:14.2", "01:14.8", "01:15.4", "01:15.9",
"01:16.5", "01:17.0", "01:17.6", "01:18.2", "01:18.7", "01:19.3",
"01:19.9", "01:20.4", "01:21.0", "01:21.5", "01:22.1", "01:22.7",
"01:23.2", "01:24.4", "01:24.9", "01:25.5", "01:26.0", "01:26.6",
"01:27.2", "01:27.7", "01:28.3", "01:28.9", "01:29.4", "01:30.0",
"01:30.5", "01:31.1", "01:31.7", "01:32.2", "01:32.8", "01:33.4",
"01:33.9", "01:34.5", "01:35.0", "01:35.6", "01:36.2", "01:36.7",
"01:37.3", "01:37.9", "01:38.4", "01:39.0", "01:39.5", "01:40.1",
"01:40.7", "01:41.2", "01:41.8", "01:42.4", "01:42.9", "01:43.5",
"01:44.0", "01:44.6", "01:45.2", "01:45.7", "01:46.3", "01:46.9",
"01:47.4", "01:48.0", "01:48.6", "01:49.1", "01:49.7", "01:50.2",
"01:50.8", "01:51.4", "01:51.9", "01:52.5", "01:53.1", "01:53.6",
"01:54.2", "01:54.7", "01:55.3", "01:55.9", "01:56.4", "01:57.0",
"01:57.6", "01:58.1", "01:58.7", "01:59.2", "01:59.8", "02:00.4",
"02:00.9", "02:01.5", "02:02.1", "02:02.6", "02:03.2", "02:03.7",
"02:04.3", "02:04.9", "02:05.4", "02:06.6", "02:07.1", "02:07.7",
"02:08.2", "02:08.8", "02:09.4", "02:09.9", "02:10.5", "02:11.1",
"02:11.6", "02:12.2", "02:12.7", "02:13.3", "02:13.9", "02:14.4",
"02:15.6", "02:16.1", "02:16.7", "02:17.2", "02:17.8", "02:18.4",
"02:18.9", "02:19.5", "02:20.1", "02:20.6", "02:21.2", "02:21.7",
"02:22.3", "02:22.9", "02:23.4", "02:24.0", "02:24.6", "02:25.1",
"02:25.7", "02:26.2", "02:26.8", "02:27.4", "02:27.9", "02:28.5",
"02:29.1", "02:29.6", "02:30.2", "02:30.7", "02:31.3", "02:31.9",
"02:32.4", "02:33.0", "02:33.6", "02:34.1", "02:34.7", "02:35.2",
"02:35.8", "02:36.4", "02:36.9", "02:37.5", "02:38.1", "02:38.6",
"02:39.2", "02:39.7", "02:40.3", "02:40.9", "02:41.4", "02:42.0",
"02:42.6", "02:43.1", "02:43.7", "02:44.2", "02:44.8", "02:45.4",
"02:45.9", "02:46.5", "02:47.1", "02:47.6", "02:48.2", "02:48.7",
"02:49.3", "02:49.9", "02:50.4", "02:51.0", "02:51.6", "02:52.1",
"02:52.7", "02:53.2", "02:53.8", "02:54.4", "02:54.9", "02:55.5",
"02:56.1", "02:56.6", "02:57.2", "02:57.7", "02:58.3", "02:58.9",
"02:59.4", "03:00.0", "03:00.6", "03:01.1", "03:01.7", "03:02.2",
"03:02.8", "03:03.4", "03:03.9", "03:04.5", "03:05.1", "03:05.6",
"03:06.2", "03:06.7", "03:07.3", "03:07.9", "03:08.4", "03:09.0",
"03:09.6", "03:10.1", "03:10.7", "03:11.2", "03:11.8", "03:12.4",
"03:12.9", "03:13.5", "03:14.1", "03:14.6", "03:15.2", "03:15.7",
"03:16.3", "03:16.9", "03:17.4", "03:18.6", "03:19.1", "03:19.7",
"03:20.2", "03:20.8", "03:21.4", "03:21.9", "03:22.5", "03:23.1",
"03:23.6", "03:24.2", "03:24.7", "03:25.3", "03:25.9", "03:26.4",
"03:27.0", "03:27.6", "03:28.1", "03:28.7", "03:29.2", "03:29.8",
"03:30.4", "03:30.9", "03:31.5", "03:32.1", "03:32.6", "03:33.2",
"03:33.7", "03:34.3", "03:34.9", "03:35.4", "03:36.0", "03:36.6",
"03:37.1", "03:37.7", "03:38.2", "03:38.8", "03:39.4", "03:39.9",
"03:40.5", "03:41.1", "03:41.6", "03:42.2", "03:42.7", "03:43.3",
"03:43.9", "03:44.4", "03:45.6", "03:46.1", "03:46.7", "03:47.2",
"03:47.8", "03:48.4", "03:48.9", "03:49.5", "03:50.1", "03:50.6",
"03:51.2", "03:51.7", "03:52.3", "03:52.9", "03:53.4", "03:54.0",
"03:54.6", "03:55.1", "03:55.7", "03:56.2", "03:56.8", "03:57.4",
"03:57.9", "03:58.5", "03:59.1", "03:59.6", "04:00.2", "04:00.7",
"04:01.3", "04:01.9", "04:02.4", "04:03.6", "04:04.1", "04:04.7",
"04:05.2", "04:05.8", "04:06.4", "04:06.9", "04:07.5", "04:08.1",
"04:08.6", "04:09.2", "04:09.7", "04:10.3", "04:10.9", "04:11.4",
"04:12.0", "04:12.6", "04:13.1", "04:13.7", "04:14.2", "04:14.8",
"04:15.4", "04:15.9", "04:16.5", "04:17.1", "04:17.6", "04:18.2",
"04:18.7", "04:19.3", "04:19.9", "04:20.4", "04:21.0", "04:21.6",
"04:22.1", "04:22.7", "04:23.2", "04:24.4", "04:24.9", "04:25.5",
"04:26.1", "04:26.6", "04:27.2", "04:27.7", "04:28.3", "04:28.9",
"04:29.4", "04:30.0", "04:30.6", "04:31.1", "04:31.7", "04:32.2"
), a = c(NA, NA, NA, NA, 1.218, 1.989, 1.786, 1.069, 0.935, 0.645,
0.645, 0.64, 0.02, 0.02, 0.02, 0.02, 0.004, 0.004, 0.004, 0.004,
0.819, 1.704, 1.752, 1.115, 0.999, 0.654, 0.41, 0.257, 0.02,
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 1.963,
1.575, 1.183, 0.788, 0.494, 0.317, 0.151, 0.02, 0.02, 0.02, 0.02,
0.02, 0.02, 0.004, 0.208, 1.042, 1.647, 1.523, 1.523, 1.516,
0.443, 0.295, 0.147, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
0.02, 0.781, 1.82, 1.727, 1.35, 0.928, 0.602, 0.507, 0.507, 0.5,
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.622, 1.754, 1.587,
1.422, 0.996, 0.64, 0.428, 0.237, 0.118, 0.02, 0.02, 0.02, 0.02,
0.02, 0.02, 0.02, 0.02, 0.02, 1.893, 1.732, 1.239, 0.831, 0.57,
0.341, 0.198, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
0.02, 0.02, 0.02, 0.02, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004,
0.004, 0.004, 0.004, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
0.02, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004,
0.004, 0.004, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.004, 0.004, 0.004,
0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.004, 0.004, 0.004, 0.006, 0.006, 0.004, 0.004, 0.004, 0.004,
0.004, 0.021, 0.021, 0.021, 0.021, 0.023, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.004, 0.004, 0.004, 0.004,
0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.006, 0.006,
0.004, 0.006, 0.021, 0.021, 0.021, 0.021, 0.021, 0.023, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.004, 0.006, 0.004, 0.004,
0.006, 0.004, 0.006, 0.004, 0.004, 0.004, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.006,
0.004, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.004, 0.006, 0.004, 0.004, 0.004,
0.004, 0.004, 0.004, 0.004, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021), b = c(NA, 52.948, 52.948, 52.948, 52.948, 52.948,
52.948, 52.948, 52.948, 52.948, 52.948, 52.963, 52.963, 52.963,
52.963, 52.963, 52.963, 52.963, 52.974, 52.974, 52.974, 52.974,
52.974, 52.974, 52.974, 52.974, 52.974, 52.974, 52.986, 52.997,
52.997, 52.997, 52.997, 52.997, 52.997, 52.997, 52.997, 52.997,
52.997, 52.997, 52.997, 52.997, 52.997, 52.983, 52.983, 52.983,
52.983, 52.983, 52.983, 52.983, 52.983, 52.983, 52.983, 52.983,
52.983, 52.983, 52.983, 52.983, 52.983, 52.983, 52.983, 52.997,
52.997, 52.997, 52.997, 52.997, 52.997, 53.012, 53.012, 53.012,
53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012,
53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012,
53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012,
53.012, 53.012, 53.012, 53.022, 53.022, 53.022, 53.022, 53.022,
53.022, 53.022, 53.022, 53.022, 53.022, 53.022, 53.022, 53.022,
52.952, 52.207, -0.016, -0.006, 0.084, 0.005, -0.025, 0.065,
0.125, 0.095, -0.025, 0.095, 0.095, -0.025, 0.125, -0.025, 0.095,
-0.025, -0.025, 0.125, -0.025, 0.095, -0.025, -0.025, 0.095,
-0.025, -0.025, 0.005, -0.025, 0.005, 0.005, 0.125, 0.005, 0.174,
0.134, 0.084, 0.134, 0.014, 0.174, 0.134, 0.054, 0.174, 0.174,
0.084, 0.084, 0.174, 0.134, 0.134, 0.204, 0.134, 0.054, 0.014,
0.174, 0.174, 0.204, 0.084, 0.014, 0.054, 0.174, 0.134, 0.054,
0.054, 0.134, 0.044, 0.014, 0.014, 0.204, 0.174, 0.014, 0.165,
0.014, 0.204, 0.014, 0.014, 0.044, 0.044, 0.024, -0.045, -0.045,
-0.045, -0.045, 0.074, 0.074, 0.104, 0.074, -0.046, -0.046, -0.017,
0.103, 0.103, 0.103, -0.048, 0.102, -0.018, -0.048, 0.102, -0.048,
0.102, -0.048, -0.048, -0.048, -0.018, 0.072, -0.048, -0.048,
0.071, -0.019, 0.061, 0.071, -0.049, -0.049, -0.049, -0.049,
-0.059, 0.1, -0.02, 0.1, 0.07, -0.02, 0.069, 0.099, 0.069, -0.051,
0.069, 0.069, 0.069, 0.069, -0.051, -0.021, -0.051, 0.099, -0.051,
0.068, -0.052, -0.022, -0.052, 0.098, 0.028, -0.022, -0.022,
0.068, -0.052, -0.052, -0.052, -0.052, 0.068, 0.098, -0.022,
0.028, -0.052, -0.022, 0.097, -0.053, 0.067, -0.023, 0.067, -0.053,
0.067, 0.067, 0.067, 0.067, -0.054, -0.024, -0.054, -0.024, 0.066,
0.096, 0.066, -0.024, -0.024, 0.066, -0.025, 0.065, -0.025, -0.025,
0.095, 0.065, 0.065, -0.055, -0.055, 0.035, 0.095, -0.055, 0.064,
-0.026, -0.056, -0.026, -0.026, 0.064, 0.064, -0.096, -0.056,
0.094, -0.086, 0.064, 0.034, -0.026, -0.026, 0.064, 0.094, 0.063,
-0.056, -0.027, 0.093, -0.057, 0.093, 0.093, 0.062, 0.092, 0.062,
-0.028, 0.092, -0.058, 0.092, 0.122, -0.058, -0.028, 0.061, -0.059,
0.091, 0.061, -0.059, 0.091, 0.061, -0.029, 0.091, 0.021, -0.03,
-0.06, 0.06, -0.06, -0.06, 0.06, 0.06, 0.06, -0.06, -0.06, 0.06,
-0.03, 0.06, 0.03, 0.06, 0.06, 0.09, 0.059, -0.06, -0.03, 0.09,
-0.03, -0.03, 0.059, -0.031, -0.061, 0.059, 0.059, 0.059, 0.089,
-0.061, -0.061, -0.031, 0.059, 0.059, -0.061, 0.059, 0.059, 0.089,
0.089, 0.059, -0.061, 0.059, 0.059, -0.031, -0.061, 0.059, -0.061,
-0.031, 0.059, -0.031, -0.031, -0.061, 0.029, 0.059, 0.089, 0.089,
0.059, 0.089, -0.061, -0.03, -0.06, 0.059, 0.059, -0.031, 0.089,
0.089, 0.06, -0.061, -0.031, -0.061, 0.089, -0.061, -0.061, 0.089,
-0.061, 0.089, 0.059, -0.061, 0.059, -0.031, 0.059, -0.031, 0.059,
-0.031, 0.059, 0.089, 0.059, 0.059, 0.059, -0.061, -0.061, -0.061,
0.059, -0.061, -0.061, 0.059, -0.031, -0.031, -0.031, -0.061,
-0.061, -0.061, -0.061, 0.059, 0.059, 0.059, 0.089, -0.061, 0.089,
0.089, -0.061, -0.031, 0.088, 0.058, 0.058, 0.088, 0.058, 0.058,
0.088, 0.088, 0.058, 0.088, -0.032, 0.058, 0.058, -0.032, 0.088,
-0.062, -0.062, -0.062, 0.088, 0.058, 0.058, 0.087, 0.087, 0.087,
-0.063, 0.057, -0.063), c = c(53.352, 53.877, 54.739, 52.626,
52.626, 52.428, 53.547, 53.547, 52.36, 51.635, 53.348, 52.951,
52.951, 53.419, 51.964, 52.36, 51.437, 53.944, 52.23, 51.704,
52.032, 53.877, 52.032, 53.348, 52.23, 52.23, 53.944, 53.944,
54.408, 54.54, 54.54, 54.341, 53.55, 52.951, 53.944, 53.082,
53.547, 52.032, 52.032, 53.28, 53.678, 51.964, 51.964, 52.951,
52.032, 53.28, 52.883, 51.765, 51.437, 53.023, 53.547, 52.559,
52.428, 52.428, 52.23, 53.352, 54.274, 53.352, 53.55, 54.274,
52.626, 54.076, 53.547, 53.221, 53.352, 53.352, 55.07, 53.419,
53.947, 54.937, 55.268, 54.014, 55.335, 53.617, 55.533, 55.335,
54.937, 55.865, 56.064, 53.617, 55.335, 52.354, 54.212, 53.617,
54.937, 53.617, 54.54, 52.428, 54.54, 53.221, 53.55, 53.352,
53.748, 54.341, 53.023, 52.428, 54.739, 54.739, 53.55, 54.341,
52.626, 53.023, 53.023, 55.666, 52.032, 53.082, 51.635, 52.752,
53.082, 52.951, 10.63, 8.444, 4.952, 5.253, 6.457, 6.457, 5.054,
5.253, 6.259, 5.054, 5.054, 6.259, 6.561, 6.259, 5.355, 6.259,
5.054, 6.259, 5.054, 5.355, 5.355, 5.054, 6.259, 6.259, 5.054,
6.457, 5.054, 5.355, 6.561, 5.355, 5.054, 5.957, 5.054, 6.457,
6.457, 6.759, 5.553, 5.553, 6.759, 6.759, 6.457, 5.253, 5.553,
5.553, 5.553, 5.253, 6.457, 6.759, 6.457, 6.457, 5.253, 6.457,
6.259, 6.457, 6.759, 6.759, 5.253, 5.253, 5.253, 5.553, 5.253,
6.457, 6.457, 6.759, 5.553, 5.253, 6.259, 6.457, 5.054, 6.759,
5.253, 6.457, 5.054, 6.759, 4.952, 5.553, 5.355, 6.06, 4.856,
4.856, 4.856, 6.259, 5.157, 4.856, 6.06, 6.362, 4.856, 5.054,
4.856, 5.157, 6.362, 6.259, 6.362, 5.157, 4.856, 4.856, 5.157,
5.964, 4.856, 4.856, 4.46, 6.362, 6.06, 4.856, 6.06, 5.157, 6.06,
6.06, 6.06, 5.157, 4.856, 4.856, 4.856, 6.362, 6.06, 5.157, 4.856,
6.06, 6.259, 6.259, 6.06, 6.362, 6.362, 6.06, 6.561, 6.06, 4.76,
4.76, 4.76, 4.76, 6.362, 6.259, 6.06, 5.054, 4.76, 5.157, 6.06,
5.157, 5.355, 5.054, 6.06, 5.054, 4.856, 6.06, 4.856, 5.054,
6.362, 6.06, 6.06, 5.054, 4.856, 6.362, 4.46, 6.561, 5.157, 4.856,
4.856, 4.856, 6.561, 6.06, 6.259, 4.856, 5.157, 5.054, 5.157,
6.06, 4.856, 5.157, 5.054, 6.06, 6.06, 5.054, 6.06, 6.362, 4.856,
6.362, 6.06, 6.06, 4.856, 4.856, 5.361, 5.157, 6.06, 5.054, 5.157,
5.054, 5.355, 5.054, 6.259, 4.856, 6.06, 4.856, 5.157, 6.259,
6.06, 5.054, 5.157, 4.856, 6.362, 6.259, 4.856, 5.758, 5.157,
6.06, 4.856, 6.06, 6.561, 6.06, 6.06, 5.054, 5.355, 5.054, 5.054,
5.157, 6.561, 5.157, 4.856, 6.561, 4.46, 6.362, 6.06, 6.561,
5.157, 6.06, 6.259, 4.856, 6.06, 5.355, 4.856, 6.06, 4.856, 6.06,
5.157, 5.054, 6.06, 6.362, 5.054, 4.856, 5.157, 5.157, 5.054,
6.259, 4.856, 6.362, 5.157, 4.856, 5.054, 6.259, 5.355, 5.157,
6.362, 5.157, 5.355, 5.355, 6.06, 4.856, 5.157, 4.856, 5.054,
5.355, 5.355, 5.054, 6.06, 4.856, 6.561, 6.362, 6.06, 6.06, 4.856,
5.054, 6.06, 6.06, 5.355, 6.06, 5.157, 5.355, 4.856, 6.259, 5.054,
5.157, 6.06, 6.06, 4.856, 6.362, 5.157, 6.561, 5.157, 5.157,
4.856, 4.856, 6.06, 4.856, 4.856, 4.856, 6.06, 6.259, 5.157,
5.157, 6.561, 6.561, 5.054, 6.362, 6.06, 5.157, 6.259, 5.054,
6.06, 5.157, 5.054, 6.06, 6.259, 5.054, 6.259, 5.355, 6.06, 6.06,
6.06, 6.259, 5.054, 5.054, 6.06, 5.054, 5.355, 6.362, 4.856,
4.856, 6.259, 4.856, 6.259, 4.856, 6.06, 6.259, 6.06, 6.06, 6.561,
4.856, 6.362, 6.561, 6.06, 5.157, 5.157, 4.856, 6.06, 6.561,
6.06, 6.259, 4.856, 4.856, 6.06, 4.856, 6.362, 6.06, 4.856, 6.561,
6.561, 4.856, 4.856, 4.856, 6.362, 6.362, 6.259, 6.362, 6.259,
6.362, 6.06, 5.157, 6.06)), class = c("spec_tbl_df", "tbl_df",
"tbl", "data.frame"), row.names = c(NA, -477L), spec = structure(list(
cols = list(DATETIME = structure(list(), class = c("collector_character",
"collector")), a = structure(list(), class = c("collector_double",
"collector")), b = structure(list(), class = c("collector_double",
"collector")), c = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1), class = "col_spec"))
在 lubridate
和 data.table
rleid
的帮助下,您可以:
library(dplyr)
library(lubridate)
df %>%
mutate(DATETIME = ms(DATETIME)) %>%
group_by(minutes = data.table::rleid(ceiling(period_to_seconds(DATETIME)/60))) %>%
summarise(across(a:c, mean, na.rm = TRUE))
# minutes a b c
# <dbl> <dbl> <dbl> <dbl>
#1 1 0.527 53.0 53.4
#2 2 0.0335 3.05 7.57
#3 3 0.0178 0.0139 5.54
#4 4 0.0162 0.0184 5.54
#5 5 0.0183 0.0204 5.75
df %>%
group_by(DATETIME = str_extract(DATETIME, "\d{2}")) %>%
summarise_all(mean, na.rm = TRUE)
# A tibble: 5 x 4
DATETIME a b c
<chr> <dbl> <dbl> <dbl>
1 00 0.527 53.0 53.4
2 01 0.0335 3.05 7.57
3 02 0.0178 0.0132 5.53
4 03 0.0163 0.0191 5.55
5 04 0.0183 0.0204 5.75
我有一个形式为 mm:ss.s 的时间序列。我想要做的是每 1 分钟 取 a 到 c 列数据的平均值。重点是59:09.9后时间会重置为00:00.0 我不知道应该如何导入这种类型的时间值,所以为了保持数据不变,我以字符形式导入时间。
数据提供如下:
structure(list(DATETIME = c("00:00.5", "00:01.1", "00:01.7",
"00:02.2", "00:02.8", "00:03.4", "00:03.9", "00:04.5", "00:05.0",
"00:05.6", "00:06.2", "00:06.7", "00:07.3", "00:07.9", "00:08.4",
"00:09.0", "00:09.5", "00:10.1", "00:10.7", "00:11.2", "00:11.8",
"00:12.4", "00:12.9", "00:13.5", "00:14.0", "00:14.6", "00:15.2",
"00:15.7", "00:16.3", "00:16.9", "00:17.4", "00:18.0", "00:18.5",
"00:19.1", "00:19.7", "00:20.2", "00:20.8", "00:21.4", "00:21.9",
"00:22.5", "00:23.0", "00:23.6", "00:24.2", "00:24.7", "00:25.3",
"00:25.9", "00:26.4", "00:27.0", "00:27.5", "00:28.1", "00:28.7",
"00:29.2", "00:29.8", "00:30.4", "00:30.9", "00:31.5", "00:32.0",
"00:32.6", "00:33.2", "00:33.7", "00:34.3", "00:34.9", "00:35.4",
"00:36.0", "00:36.5", "00:37.1", "00:37.7", "00:38.2", "00:38.8",
"00:39.4", "00:39.9", "00:40.5", "00:41.1", "00:41.6", "00:42.2",
"00:42.7", "00:43.3", "00:43.9", "00:44.4", "00:45.0", "00:45.5",
"00:46.1", "00:46.7", "00:47.2", "00:47.8", "00:48.4", "00:48.9",
"00:49.5", "00:50.0", "00:50.6", "00:51.2", "00:51.7", "00:52.3",
"00:52.9", "00:53.4", "00:54.0", "00:54.5", "00:55.1", "00:55.7",
"00:56.2", "00:56.8", "00:57.4", "00:57.9", "00:58.5", "00:59.0",
"00:59.6", "01:00.2", "01:00.7", "01:01.3", "01:01.9", "01:02.4",
"01:03.0", "01:03.5", "01:04.1", "01:04.7", "01:05.2", "01:05.8",
"01:06.4", "01:06.9", "01:07.5", "01:08.0", "01:08.6", "01:09.2",
"01:09.7", "01:10.3", "01:10.9", "01:11.4", "01:12.0", "01:12.5",
"01:13.1", "01:13.7", "01:14.2", "01:14.8", "01:15.4", "01:15.9",
"01:16.5", "01:17.0", "01:17.6", "01:18.2", "01:18.7", "01:19.3",
"01:19.9", "01:20.4", "01:21.0", "01:21.5", "01:22.1", "01:22.7",
"01:23.2", "01:24.4", "01:24.9", "01:25.5", "01:26.0", "01:26.6",
"01:27.2", "01:27.7", "01:28.3", "01:28.9", "01:29.4", "01:30.0",
"01:30.5", "01:31.1", "01:31.7", "01:32.2", "01:32.8", "01:33.4",
"01:33.9", "01:34.5", "01:35.0", "01:35.6", "01:36.2", "01:36.7",
"01:37.3", "01:37.9", "01:38.4", "01:39.0", "01:39.5", "01:40.1",
"01:40.7", "01:41.2", "01:41.8", "01:42.4", "01:42.9", "01:43.5",
"01:44.0", "01:44.6", "01:45.2", "01:45.7", "01:46.3", "01:46.9",
"01:47.4", "01:48.0", "01:48.6", "01:49.1", "01:49.7", "01:50.2",
"01:50.8", "01:51.4", "01:51.9", "01:52.5", "01:53.1", "01:53.6",
"01:54.2", "01:54.7", "01:55.3", "01:55.9", "01:56.4", "01:57.0",
"01:57.6", "01:58.1", "01:58.7", "01:59.2", "01:59.8", "02:00.4",
"02:00.9", "02:01.5", "02:02.1", "02:02.6", "02:03.2", "02:03.7",
"02:04.3", "02:04.9", "02:05.4", "02:06.6", "02:07.1", "02:07.7",
"02:08.2", "02:08.8", "02:09.4", "02:09.9", "02:10.5", "02:11.1",
"02:11.6", "02:12.2", "02:12.7", "02:13.3", "02:13.9", "02:14.4",
"02:15.6", "02:16.1", "02:16.7", "02:17.2", "02:17.8", "02:18.4",
"02:18.9", "02:19.5", "02:20.1", "02:20.6", "02:21.2", "02:21.7",
"02:22.3", "02:22.9", "02:23.4", "02:24.0", "02:24.6", "02:25.1",
"02:25.7", "02:26.2", "02:26.8", "02:27.4", "02:27.9", "02:28.5",
"02:29.1", "02:29.6", "02:30.2", "02:30.7", "02:31.3", "02:31.9",
"02:32.4", "02:33.0", "02:33.6", "02:34.1", "02:34.7", "02:35.2",
"02:35.8", "02:36.4", "02:36.9", "02:37.5", "02:38.1", "02:38.6",
"02:39.2", "02:39.7", "02:40.3", "02:40.9", "02:41.4", "02:42.0",
"02:42.6", "02:43.1", "02:43.7", "02:44.2", "02:44.8", "02:45.4",
"02:45.9", "02:46.5", "02:47.1", "02:47.6", "02:48.2", "02:48.7",
"02:49.3", "02:49.9", "02:50.4", "02:51.0", "02:51.6", "02:52.1",
"02:52.7", "02:53.2", "02:53.8", "02:54.4", "02:54.9", "02:55.5",
"02:56.1", "02:56.6", "02:57.2", "02:57.7", "02:58.3", "02:58.9",
"02:59.4", "03:00.0", "03:00.6", "03:01.1", "03:01.7", "03:02.2",
"03:02.8", "03:03.4", "03:03.9", "03:04.5", "03:05.1", "03:05.6",
"03:06.2", "03:06.7", "03:07.3", "03:07.9", "03:08.4", "03:09.0",
"03:09.6", "03:10.1", "03:10.7", "03:11.2", "03:11.8", "03:12.4",
"03:12.9", "03:13.5", "03:14.1", "03:14.6", "03:15.2", "03:15.7",
"03:16.3", "03:16.9", "03:17.4", "03:18.6", "03:19.1", "03:19.7",
"03:20.2", "03:20.8", "03:21.4", "03:21.9", "03:22.5", "03:23.1",
"03:23.6", "03:24.2", "03:24.7", "03:25.3", "03:25.9", "03:26.4",
"03:27.0", "03:27.6", "03:28.1", "03:28.7", "03:29.2", "03:29.8",
"03:30.4", "03:30.9", "03:31.5", "03:32.1", "03:32.6", "03:33.2",
"03:33.7", "03:34.3", "03:34.9", "03:35.4", "03:36.0", "03:36.6",
"03:37.1", "03:37.7", "03:38.2", "03:38.8", "03:39.4", "03:39.9",
"03:40.5", "03:41.1", "03:41.6", "03:42.2", "03:42.7", "03:43.3",
"03:43.9", "03:44.4", "03:45.6", "03:46.1", "03:46.7", "03:47.2",
"03:47.8", "03:48.4", "03:48.9", "03:49.5", "03:50.1", "03:50.6",
"03:51.2", "03:51.7", "03:52.3", "03:52.9", "03:53.4", "03:54.0",
"03:54.6", "03:55.1", "03:55.7", "03:56.2", "03:56.8", "03:57.4",
"03:57.9", "03:58.5", "03:59.1", "03:59.6", "04:00.2", "04:00.7",
"04:01.3", "04:01.9", "04:02.4", "04:03.6", "04:04.1", "04:04.7",
"04:05.2", "04:05.8", "04:06.4", "04:06.9", "04:07.5", "04:08.1",
"04:08.6", "04:09.2", "04:09.7", "04:10.3", "04:10.9", "04:11.4",
"04:12.0", "04:12.6", "04:13.1", "04:13.7", "04:14.2", "04:14.8",
"04:15.4", "04:15.9", "04:16.5", "04:17.1", "04:17.6", "04:18.2",
"04:18.7", "04:19.3", "04:19.9", "04:20.4", "04:21.0", "04:21.6",
"04:22.1", "04:22.7", "04:23.2", "04:24.4", "04:24.9", "04:25.5",
"04:26.1", "04:26.6", "04:27.2", "04:27.7", "04:28.3", "04:28.9",
"04:29.4", "04:30.0", "04:30.6", "04:31.1", "04:31.7", "04:32.2"
), a = c(NA, NA, NA, NA, 1.218, 1.989, 1.786, 1.069, 0.935, 0.645,
0.645, 0.64, 0.02, 0.02, 0.02, 0.02, 0.004, 0.004, 0.004, 0.004,
0.819, 1.704, 1.752, 1.115, 0.999, 0.654, 0.41, 0.257, 0.02,
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 1.963,
1.575, 1.183, 0.788, 0.494, 0.317, 0.151, 0.02, 0.02, 0.02, 0.02,
0.02, 0.02, 0.004, 0.208, 1.042, 1.647, 1.523, 1.523, 1.516,
0.443, 0.295, 0.147, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
0.02, 0.781, 1.82, 1.727, 1.35, 0.928, 0.602, 0.507, 0.507, 0.5,
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.622, 1.754, 1.587,
1.422, 0.996, 0.64, 0.428, 0.237, 0.118, 0.02, 0.02, 0.02, 0.02,
0.02, 0.02, 0.02, 0.02, 0.02, 1.893, 1.732, 1.239, 0.831, 0.57,
0.341, 0.198, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
0.02, 0.02, 0.02, 0.02, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004,
0.004, 0.004, 0.004, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
0.02, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004,
0.004, 0.004, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.004, 0.004, 0.004,
0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.004, 0.004, 0.004, 0.006, 0.006, 0.004, 0.004, 0.004, 0.004,
0.004, 0.021, 0.021, 0.021, 0.021, 0.023, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.004, 0.004, 0.004, 0.004,
0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.006, 0.006,
0.004, 0.006, 0.021, 0.021, 0.021, 0.021, 0.021, 0.023, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.004, 0.006, 0.004, 0.004,
0.006, 0.004, 0.006, 0.004, 0.004, 0.004, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.006,
0.004, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.004, 0.006, 0.004, 0.004, 0.004,
0.004, 0.004, 0.004, 0.004, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021, 0.021,
0.021, 0.021), b = c(NA, 52.948, 52.948, 52.948, 52.948, 52.948,
52.948, 52.948, 52.948, 52.948, 52.948, 52.963, 52.963, 52.963,
52.963, 52.963, 52.963, 52.963, 52.974, 52.974, 52.974, 52.974,
52.974, 52.974, 52.974, 52.974, 52.974, 52.974, 52.986, 52.997,
52.997, 52.997, 52.997, 52.997, 52.997, 52.997, 52.997, 52.997,
52.997, 52.997, 52.997, 52.997, 52.997, 52.983, 52.983, 52.983,
52.983, 52.983, 52.983, 52.983, 52.983, 52.983, 52.983, 52.983,
52.983, 52.983, 52.983, 52.983, 52.983, 52.983, 52.983, 52.997,
52.997, 52.997, 52.997, 52.997, 52.997, 53.012, 53.012, 53.012,
53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012,
53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012,
53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012, 53.012,
53.012, 53.012, 53.012, 53.022, 53.022, 53.022, 53.022, 53.022,
53.022, 53.022, 53.022, 53.022, 53.022, 53.022, 53.022, 53.022,
52.952, 52.207, -0.016, -0.006, 0.084, 0.005, -0.025, 0.065,
0.125, 0.095, -0.025, 0.095, 0.095, -0.025, 0.125, -0.025, 0.095,
-0.025, -0.025, 0.125, -0.025, 0.095, -0.025, -0.025, 0.095,
-0.025, -0.025, 0.005, -0.025, 0.005, 0.005, 0.125, 0.005, 0.174,
0.134, 0.084, 0.134, 0.014, 0.174, 0.134, 0.054, 0.174, 0.174,
0.084, 0.084, 0.174, 0.134, 0.134, 0.204, 0.134, 0.054, 0.014,
0.174, 0.174, 0.204, 0.084, 0.014, 0.054, 0.174, 0.134, 0.054,
0.054, 0.134, 0.044, 0.014, 0.014, 0.204, 0.174, 0.014, 0.165,
0.014, 0.204, 0.014, 0.014, 0.044, 0.044, 0.024, -0.045, -0.045,
-0.045, -0.045, 0.074, 0.074, 0.104, 0.074, -0.046, -0.046, -0.017,
0.103, 0.103, 0.103, -0.048, 0.102, -0.018, -0.048, 0.102, -0.048,
0.102, -0.048, -0.048, -0.048, -0.018, 0.072, -0.048, -0.048,
0.071, -0.019, 0.061, 0.071, -0.049, -0.049, -0.049, -0.049,
-0.059, 0.1, -0.02, 0.1, 0.07, -0.02, 0.069, 0.099, 0.069, -0.051,
0.069, 0.069, 0.069, 0.069, -0.051, -0.021, -0.051, 0.099, -0.051,
0.068, -0.052, -0.022, -0.052, 0.098, 0.028, -0.022, -0.022,
0.068, -0.052, -0.052, -0.052, -0.052, 0.068, 0.098, -0.022,
0.028, -0.052, -0.022, 0.097, -0.053, 0.067, -0.023, 0.067, -0.053,
0.067, 0.067, 0.067, 0.067, -0.054, -0.024, -0.054, -0.024, 0.066,
0.096, 0.066, -0.024, -0.024, 0.066, -0.025, 0.065, -0.025, -0.025,
0.095, 0.065, 0.065, -0.055, -0.055, 0.035, 0.095, -0.055, 0.064,
-0.026, -0.056, -0.026, -0.026, 0.064, 0.064, -0.096, -0.056,
0.094, -0.086, 0.064, 0.034, -0.026, -0.026, 0.064, 0.094, 0.063,
-0.056, -0.027, 0.093, -0.057, 0.093, 0.093, 0.062, 0.092, 0.062,
-0.028, 0.092, -0.058, 0.092, 0.122, -0.058, -0.028, 0.061, -0.059,
0.091, 0.061, -0.059, 0.091, 0.061, -0.029, 0.091, 0.021, -0.03,
-0.06, 0.06, -0.06, -0.06, 0.06, 0.06, 0.06, -0.06, -0.06, 0.06,
-0.03, 0.06, 0.03, 0.06, 0.06, 0.09, 0.059, -0.06, -0.03, 0.09,
-0.03, -0.03, 0.059, -0.031, -0.061, 0.059, 0.059, 0.059, 0.089,
-0.061, -0.061, -0.031, 0.059, 0.059, -0.061, 0.059, 0.059, 0.089,
0.089, 0.059, -0.061, 0.059, 0.059, -0.031, -0.061, 0.059, -0.061,
-0.031, 0.059, -0.031, -0.031, -0.061, 0.029, 0.059, 0.089, 0.089,
0.059, 0.089, -0.061, -0.03, -0.06, 0.059, 0.059, -0.031, 0.089,
0.089, 0.06, -0.061, -0.031, -0.061, 0.089, -0.061, -0.061, 0.089,
-0.061, 0.089, 0.059, -0.061, 0.059, -0.031, 0.059, -0.031, 0.059,
-0.031, 0.059, 0.089, 0.059, 0.059, 0.059, -0.061, -0.061, -0.061,
0.059, -0.061, -0.061, 0.059, -0.031, -0.031, -0.031, -0.061,
-0.061, -0.061, -0.061, 0.059, 0.059, 0.059, 0.089, -0.061, 0.089,
0.089, -0.061, -0.031, 0.088, 0.058, 0.058, 0.088, 0.058, 0.058,
0.088, 0.088, 0.058, 0.088, -0.032, 0.058, 0.058, -0.032, 0.088,
-0.062, -0.062, -0.062, 0.088, 0.058, 0.058, 0.087, 0.087, 0.087,
-0.063, 0.057, -0.063), c = c(53.352, 53.877, 54.739, 52.626,
52.626, 52.428, 53.547, 53.547, 52.36, 51.635, 53.348, 52.951,
52.951, 53.419, 51.964, 52.36, 51.437, 53.944, 52.23, 51.704,
52.032, 53.877, 52.032, 53.348, 52.23, 52.23, 53.944, 53.944,
54.408, 54.54, 54.54, 54.341, 53.55, 52.951, 53.944, 53.082,
53.547, 52.032, 52.032, 53.28, 53.678, 51.964, 51.964, 52.951,
52.032, 53.28, 52.883, 51.765, 51.437, 53.023, 53.547, 52.559,
52.428, 52.428, 52.23, 53.352, 54.274, 53.352, 53.55, 54.274,
52.626, 54.076, 53.547, 53.221, 53.352, 53.352, 55.07, 53.419,
53.947, 54.937, 55.268, 54.014, 55.335, 53.617, 55.533, 55.335,
54.937, 55.865, 56.064, 53.617, 55.335, 52.354, 54.212, 53.617,
54.937, 53.617, 54.54, 52.428, 54.54, 53.221, 53.55, 53.352,
53.748, 54.341, 53.023, 52.428, 54.739, 54.739, 53.55, 54.341,
52.626, 53.023, 53.023, 55.666, 52.032, 53.082, 51.635, 52.752,
53.082, 52.951, 10.63, 8.444, 4.952, 5.253, 6.457, 6.457, 5.054,
5.253, 6.259, 5.054, 5.054, 6.259, 6.561, 6.259, 5.355, 6.259,
5.054, 6.259, 5.054, 5.355, 5.355, 5.054, 6.259, 6.259, 5.054,
6.457, 5.054, 5.355, 6.561, 5.355, 5.054, 5.957, 5.054, 6.457,
6.457, 6.759, 5.553, 5.553, 6.759, 6.759, 6.457, 5.253, 5.553,
5.553, 5.553, 5.253, 6.457, 6.759, 6.457, 6.457, 5.253, 6.457,
6.259, 6.457, 6.759, 6.759, 5.253, 5.253, 5.253, 5.553, 5.253,
6.457, 6.457, 6.759, 5.553, 5.253, 6.259, 6.457, 5.054, 6.759,
5.253, 6.457, 5.054, 6.759, 4.952, 5.553, 5.355, 6.06, 4.856,
4.856, 4.856, 6.259, 5.157, 4.856, 6.06, 6.362, 4.856, 5.054,
4.856, 5.157, 6.362, 6.259, 6.362, 5.157, 4.856, 4.856, 5.157,
5.964, 4.856, 4.856, 4.46, 6.362, 6.06, 4.856, 6.06, 5.157, 6.06,
6.06, 6.06, 5.157, 4.856, 4.856, 4.856, 6.362, 6.06, 5.157, 4.856,
6.06, 6.259, 6.259, 6.06, 6.362, 6.362, 6.06, 6.561, 6.06, 4.76,
4.76, 4.76, 4.76, 6.362, 6.259, 6.06, 5.054, 4.76, 5.157, 6.06,
5.157, 5.355, 5.054, 6.06, 5.054, 4.856, 6.06, 4.856, 5.054,
6.362, 6.06, 6.06, 5.054, 4.856, 6.362, 4.46, 6.561, 5.157, 4.856,
4.856, 4.856, 6.561, 6.06, 6.259, 4.856, 5.157, 5.054, 5.157,
6.06, 4.856, 5.157, 5.054, 6.06, 6.06, 5.054, 6.06, 6.362, 4.856,
6.362, 6.06, 6.06, 4.856, 4.856, 5.361, 5.157, 6.06, 5.054, 5.157,
5.054, 5.355, 5.054, 6.259, 4.856, 6.06, 4.856, 5.157, 6.259,
6.06, 5.054, 5.157, 4.856, 6.362, 6.259, 4.856, 5.758, 5.157,
6.06, 4.856, 6.06, 6.561, 6.06, 6.06, 5.054, 5.355, 5.054, 5.054,
5.157, 6.561, 5.157, 4.856, 6.561, 4.46, 6.362, 6.06, 6.561,
5.157, 6.06, 6.259, 4.856, 6.06, 5.355, 4.856, 6.06, 4.856, 6.06,
5.157, 5.054, 6.06, 6.362, 5.054, 4.856, 5.157, 5.157, 5.054,
6.259, 4.856, 6.362, 5.157, 4.856, 5.054, 6.259, 5.355, 5.157,
6.362, 5.157, 5.355, 5.355, 6.06, 4.856, 5.157, 4.856, 5.054,
5.355, 5.355, 5.054, 6.06, 4.856, 6.561, 6.362, 6.06, 6.06, 4.856,
5.054, 6.06, 6.06, 5.355, 6.06, 5.157, 5.355, 4.856, 6.259, 5.054,
5.157, 6.06, 6.06, 4.856, 6.362, 5.157, 6.561, 5.157, 5.157,
4.856, 4.856, 6.06, 4.856, 4.856, 4.856, 6.06, 6.259, 5.157,
5.157, 6.561, 6.561, 5.054, 6.362, 6.06, 5.157, 6.259, 5.054,
6.06, 5.157, 5.054, 6.06, 6.259, 5.054, 6.259, 5.355, 6.06, 6.06,
6.06, 6.259, 5.054, 5.054, 6.06, 5.054, 5.355, 6.362, 4.856,
4.856, 6.259, 4.856, 6.259, 4.856, 6.06, 6.259, 6.06, 6.06, 6.561,
4.856, 6.362, 6.561, 6.06, 5.157, 5.157, 4.856, 6.06, 6.561,
6.06, 6.259, 4.856, 4.856, 6.06, 4.856, 6.362, 6.06, 4.856, 6.561,
6.561, 4.856, 4.856, 4.856, 6.362, 6.362, 6.259, 6.362, 6.259,
6.362, 6.06, 5.157, 6.06)), class = c("spec_tbl_df", "tbl_df",
"tbl", "data.frame"), row.names = c(NA, -477L), spec = structure(list(
cols = list(DATETIME = structure(list(), class = c("collector_character",
"collector")), a = structure(list(), class = c("collector_double",
"collector")), b = structure(list(), class = c("collector_double",
"collector")), c = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1), class = "col_spec"))
在 lubridate
和 data.table
rleid
的帮助下,您可以:
library(dplyr)
library(lubridate)
df %>%
mutate(DATETIME = ms(DATETIME)) %>%
group_by(minutes = data.table::rleid(ceiling(period_to_seconds(DATETIME)/60))) %>%
summarise(across(a:c, mean, na.rm = TRUE))
# minutes a b c
# <dbl> <dbl> <dbl> <dbl>
#1 1 0.527 53.0 53.4
#2 2 0.0335 3.05 7.57
#3 3 0.0178 0.0139 5.54
#4 4 0.0162 0.0184 5.54
#5 5 0.0183 0.0204 5.75
df %>%
group_by(DATETIME = str_extract(DATETIME, "\d{2}")) %>%
summarise_all(mean, na.rm = TRUE)
# A tibble: 5 x 4
DATETIME a b c
<chr> <dbl> <dbl> <dbl>
1 00 0.527 53.0 53.4
2 01 0.0335 3.05 7.57
3 02 0.0178 0.0132 5.53
4 03 0.0163 0.0191 5.55
5 04 0.0183 0.0204 5.75