How should the data be ordered for that? For example here we have first REM ending before next ends?
Or is the data already correctly ordered (I just changed the format here to be date time)? We are missing date information so how can be differentiate when day is changing or should we guess it based on the timestamps?
Edit: Going with the original order of data and only caring about checking end and next start
Names Default To Here(1);
dt = Open("$DOWNLOADS/example(1).jmp");
m_sub = dt[0, "SubType"];
rem_rows = Loc(m_sub, "REM");
rem_ends = dt[rem_rows, "Time of Day[End]"];
rem_starts = dt[rem_rows, "Time of Day[Start]"];
Remove From(rem_ends, N Items(rem_starts));
Remove From(rem_starts, 1);
rem_durs = (rem_starts - rem_ends);
new_col = dt << New Column("Counts", Numeric, Continuous);
For Each({rem_dur, idx}, rem_durs,
If(rem_dur < In Minutes(15) & rem_dur >= 0,
row_start = rem_rows[idx];
row_end = rem_rows[idx + 1];
ntwos = Loc(m_sub[row_start::row_end], "Stadium N2");
ntwo_count = N Items(ntwos);
dt[row_start::row_end, "Counts"] = ntwo_count;
);
);
-Jarmo