For subsequent discussion, I will refer to the example data frame below:
Now, what I wish to achieve is to group all the packet times that are similar - i.e. all the 7s, 12s, etc. Furthermore, the PacketTime field should contain the difference in min and max (max(PacketTime) - min(PacketTime)), and the FrameLen, IPLen and TCPLen fields should be lists of all the values that correspond to the grouped time. For example for the 7s group, FrameLen would contain c(304, 276, 276).
My solution for the above is as follows:
df <- packets %>%
group_by(round(PacketTime)) %>%
summarise(
PTime=max(PacketTime)-min(PacketTime),
FLen=list(FrameLen),
ILen=list(IPLen),
Movement=0
) %>%
rename(PacketTime=PTime) %>%
rename(FrameLen=FLen) %>%
rename(IPLen=ILen)
df$"round(PacketTime)" <- NULL # Remove the group_by
However, some of these crossover (i.e. 1480s also includes part of 1481s). The part here, which makes this a little easier (in some regard) is that each of the groups are separated by 5s timing window (via Python time.sleep(5)).
How can I achieve the previous result, but only relying on the 5s difference between the groups that also takes into account the crossover?
EDIT: As suggested by Ben, here is the dput() of my dataframe df[1:20,]:
structure(list(PacketTime = c(7.083779, 7.147268, 7.147462, 12.084768,
12.153246, 12.153951, 17.095972, 17.159268, 17.159876, 22.11384,
22.176926, 22.177467, 27.134427, 27.199108, 27.200064, 32.144442,
32.208648, 32.20922, 37.144255, 37.205622), FrameLen = c(304L,
276L, 276L, 304L, 276L, 276L, 304L, 276L, 276L, 304L, 276L, 276L,
304L, 276L, 276L, 304L, 276L, 276L, 304L, 276L), IPLen = c(300L,
272L, 272L, 300L, 272L, 272L, 300L, 272L, 272L, 300L, 272L, 272L,
300L, 272L, 272L, 300L, 272L, 272L, 300L, 272L), TCPLen = c(260L,
232L, 232L, 260L, 232L, 232L, 260L, 232L, 232L, 260L, 232L, 232L,
260L, 232L, 232L, 260L, 232L, 232L, 260L, 232L), Movement = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), row.names = c(NA,
20L), class = "data.frame")
