<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Count occurence between 2 other occurences based on time period in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711493#M89509</link>
    <description>&lt;P&gt;Here you are!&lt;/P&gt;</description>
    <pubDate>Thu, 21 Dec 2023 13:15:57 GMT</pubDate>
    <dc:creator>vcoppens</dc:creator>
    <dc:date>2023-12-21T13:15:57Z</dc:date>
    <item>
      <title>Count occurence between 2 other occurences based on time period</title>
      <link>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711445#M89504</link>
      <description>&lt;P&gt;🙋‍:female_sign:&lt;/img&gt;Hi!&lt;BR /&gt;Within the column "Subtype", I need to count the number of times "Stadium N2" appears between 2 occurences of the word "REM", only when the time in column "Start" of the second REM occurence is within 15 minutes of the time in column "End" of the first REM occurence.&lt;/P&gt;&lt;P&gt;See stars in screenshot: in this case, the count would be 3&lt;BR /&gt;What is the formula to do so?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx :hugging_face:&lt;/img&gt;:folded_hands:&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 10:55:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711445#M89504</guid>
      <dc:creator>vcoppens</dc:creator>
      <dc:date>2023-12-21T10:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count occurence between 2 other occurences based on time period</title>
      <link>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711458#M89506</link>
      <description>&lt;P&gt;Could you provide example data to make testing easier?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 11:35:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711458#M89506</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-12-21T11:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Count occurence between 2 other occurences based on time period</title>
      <link>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711493#M89509</link>
      <description>&lt;P&gt;Here you are!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 13:15:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711493#M89509</guid>
      <dc:creator>vcoppens</dc:creator>
      <dc:date>2023-12-21T13:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Count occurence between 2 other occurences based on time period</title>
      <link>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711525#M89510</link>
      <description>&lt;P&gt;One more question, is cumulative value fine? So on first Stadium N2 between two REMs it would be 1 and second 2 and so on?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 13:44:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711525#M89510</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-12-21T13:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Count occurence between 2 other occurences based on time period</title>
      <link>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711540#M89512</link>
      <description>&lt;P&gt;This is definitely not the only option, but depending on the amount of data you have, something like this might work where you add two columns to your table&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

Current Data Table() &amp;lt;&amp;lt; New Column("R", Numeric, Continuous, Formula(
	Col Cumulative Sum(If(:SubType == "REM", 1, .))
));

Current Data Table() &amp;lt;&amp;lt; New Column("c_n2", Numeric, Continuous, Formula(
	If(!IsMissing(:R),
		Col Sum(If(:SubType == "Stadium N2", 1, 0), :R);
	,
		.
	);
));
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Dec 2023 13:51:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711540#M89512</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-12-21T13:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Count occurence between 2 other occurences based on time period</title>
      <link>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711546#M89514</link>
      <description>&lt;P&gt;Thank you for the suggestion, this indeed identifies all N2 intermittent to REM :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;I however need to count only those that are in between 2 REM which are maximum 15 minutes apart (most of the REM End times and following REM start times are &amp;gt; 15 minutes apart).&lt;/P&gt;&lt;P&gt;How would you integrate this time filter?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 14:03:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711546#M89514</guid>
      <dc:creator>vcoppens</dc:creator>
      <dc:date>2023-12-21T14:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Count occurence between 2 other occurences based on time period</title>
      <link>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711554#M89517</link>
      <description>&lt;P&gt;How should the data be ordered for that? For example here we have first REM ending before next ends?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1703170838554.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/60015iD05D583B5AFB4612/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1703170838554.png" alt="jthi_0-1703170838554.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1703170872123.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/60016i095D730B22C755E8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1703170872123.png" alt="jthi_1-1703170872123.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Going with the original order of data and only caring about checking end and next start&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;&amp;lt; New Column("Counts", Numeric, Continuous);

For Each({rem_dur, idx}, rem_durs,
	If(rem_dur &amp;lt; In Minutes(15) &amp;amp; rem_dur &amp;gt;= 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;
	);
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Dec 2023 15:12:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711554#M89517</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-12-21T15:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Count occurence between 2 other occurences based on time period</title>
      <link>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711572#M89521</link>
      <description>&lt;P&gt;THank you! Values were indeed already ordered by Start.&lt;/P&gt;&lt;P&gt;Small add-on question: I need to verify manually for correctness but can only do this after grouping by other columns :ID, :Validated, :Subtype&lt;/P&gt;&lt;P&gt;where and how would I fit in the grouping by?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 15:53:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711572#M89521</guid>
      <dc:creator>vcoppens</dc:creator>
      <dc:date>2023-12-21T15:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Count occurence between 2 other occurences based on time period</title>
      <link>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711643#M89522</link>
      <description>&lt;P&gt;Adding grouping variables would require quite a lot of changes to the script. Easiest option would most likely be to add create subset for each group, run the calculation for those and then join those back to original data table (might be necessary to add some sort of unique identifier column). Other fairly easy option would be to create single GROUP column and then loop over the different options using that BUT one must be careful with the indices.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 16:29:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Count-occurence-between-2-other-occurences-based-on-time-period/m-p/711643#M89522</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-12-21T16:29:48Z</dc:date>
    </item>
  </channel>
</rss>

