Hello, I am beginner with R and now I am struggling with a new problem.
I have many data.frame structured like the example below.
Every data frame is a long consecutive repetition (approx. 80000 rows per file) of measurements taken from different ports (in the example, only from port 1 to 5). Every cycle from port 1 to 5 is repeated multiple times.
I would like to find the way to filter only the last 3 values of every port in each repeated cycle, and later to calculate the mean between the 3 values.
My problem is how to tell R that every cycle is kind of independent. I tried to dplyr::filter each port but I don’t know how to explain R that I have consecutive cycles. I hope it is possible.
Otherwise I thought to find a way to identify each consecutive cycle, so later I could work on the data in according to the number of cycle. Would it be possible?
Thank you
date time port nh3
1 28.01.2019 09:44:52.657 1 361.9
2 28.01.2019 09:44:54.206 1 358.6
3 28.01.2019 09:44:56.012 1 363.6
4 28.01.2019 09:44:57.836 1 368.0
5 28.01.2019 09:44:59.637 1 371.8
6 28.01.2019 09:45:01.427 2 374.8
7 28.01.2019 09:45:03.226 2 378.4
8 28.01.2019 09:45:05.026 2 381.8
9 28.01.2019 09:45:06.828 2 386.3
10 28.01.2019 09:45:08.637 2 390.3
11 28.01.2019 09:45:10.457 2 396.3
12 28.01.2019 09:45:12.269 2 399.1
13 28.01.2019 09:45:13.917 3 399.1
14 28.01.2019 09:45:15.483 3 399.2
15 28.01.2019 09:45:17.315 3 398.1
16 28.01.2019 09:45:19.125 3 397.5
17 28.01.2019 09:45:20.934 3 396.1
18 28.01.2019 09:45:22.755 4 394.9
19 28.01.2019 09:45:24.563 4 390.6
20 28.01.2019 09:45:26.378 4 387.1
21 28.01.2019 09:45:28.193 4 384.9
22 28.01.2019 09:45:30.013 4 382.7
23 28.01.2019 09:45:31.812 5 381.8
24 28.01.2019 09:45:33.615 5 380.6
25 28.01.2019 09:45:35.276 5 380.6
26 28.01.2019 09:45:36.834 5 382.2
27 28.01.2019 09:45:38.647 5 385.5
28 28.01.2019 09:45:40.456 5 387.0
29 28.01.2019 09:45:42.266 1 386.3
30 28.01.2019 09:45:44.065 1 384.6
31 28.01.2019 09:45:45.875 1 382.4
32 28.01.2019 09:45:47.703 2 381.1
33 28.01.2019 09:45:49.516 2 380.5
34 28.01.2019 09:45:53.167 2 375.2
35 28.01.2019 09:45:54.973 2 370.8
36 28.01.2019 09:45:56.615 2 370.8
37 28.01.2019 09:45:58.157 3 413.1
38 28.01.2019 09:45:59.956 3 439.2
39 28.01.2019 09:46:01.755 3 470.7
40 28.01.2019 09:46:03.585 3 473.6
41 28.01.2019 09:46:05.408 4 482.6
42 28.01.2019 09:46:07.232 4 483.1
43 28.01.2019 09:46:09.055 4 506.0
44 28.01.2019 09:46:10.869 4 504.6
45 28.01.2019 09:46:12.693 4 504.
46 28.01.2019 09:46:14.510 5 508.7
47 28.01.2019 09:46:16.332 5 508.5
48 28.01.2019 09:46:18.006 5 508.5
49 28.01.2019 09:46:19.581 5 503.9
50 28.01.2019 09:46:21.395 5 502.4
51 28.01.2019 09:46:23.214 5 494.9