I am trying to extract certain data from a large data set using R. The data is from a process which goes through several phases, lets say phase 0 to 5. I have a data set which contains multiple runs of the process.
I am trying to extract the data for each of the runs. I want to create subsets with the first occurrence of phase 0 to 5 and then an other subset with again the phases 0 to 5 (of the second run). The data set only contains the process data and the phase number in chronological order, it does not tell which run it is in. However, the phases are in order, so the phase column goes from 0 to 5 and then starts at 0 again.
I have already tried to organize the data using some while and for loops, however this is very slow on such a large data set (700 000 entries). Even using a small section of only 10000 entries or so takes quite long.
the data set may look something like this (second column is the phase):
01, 0, 2, 4, 5, 3, 4,
02, 0, 3, 4, 5, 2, 2,
03, 0, 4, 5, 4, 9, 8,
04, 1, 8, 9, 2, 7, 3,
05, 1, 8, 7, 0, 7, 8,
06, 2, 8, 4, 9, 7, 8,
07, 2, 9, 7, 5, 0, 8,
08, 2, 8, 6, 5, 7, 9,
07, 2, 8, 7, 6, 7, 9,
08, 3, 7, 8, 6, 7, 9,
09, 3, 7, 9, 8, 7, 8,
10, 4, 5, 6, 7, 4, 3,
11, 4, 6, 7, 5, 6, 4,
12, 5, 6, 4, 3, 2, 2,
13, 0, 6, 3, 3, 2, 5,
14, 0, 5, 6, 3, 2, 2,
15, 1, 5, 2, 1, 4, 4,
note that the number of lines per phase are not constant.
The subsets i would expect from above example would be:
01, 0, 2, 4, 5, 3, 4,
02, 0, 3, 4, 5, 2, 2,
03, 0, 4, 5, 4, 9, 8,
04, 1, 8, 9, 2, 7, 3,
05, 1, 8, 7, 0, 7, 8,
06, 2, 8, 4, 9, 7, 8,
07, 2, 9, 7, 5, 0, 8,
08, 2, 8, 6, 5, 7, 9,
07, 2, 8, 7, 6, 7, 9,
08, 3, 7, 8, 6, 7, 9,
09, 3, 7, 9, 8, 7, 8,
10, 4, 5, 6, 7, 4, 3,
11, 4, 6, 7, 5, 6, 4,
12, 5, 6, 4, 3, 2, 2,
and
13, 0, 6, 3, 3, 2, 5,
14, 0, 5, 6, 3, 2, 2,
15, 1, 5, 2, 1, 4, 4,
(note: in the original data set the phase will always end at 5)