<?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 update table based on timestamp in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453462#M70038</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have two tables. (A and B)&lt;/P&gt;&lt;P&gt;Table A contain (2000events along the duration of a test) events marking the beginning of a period and the name of the period at specific timestamps&amp;nbsp;(underlined line is header)&lt;/P&gt;&lt;P&gt;&lt;U&gt;TimeStamp, Period&lt;/U&gt;&lt;/P&gt;&lt;P&gt;30-12-2021 17:35:49.1, A&amp;nbsp;&lt;/P&gt;&lt;P&gt;30-12-2021 17:39:36.8, B&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;so Period A is between "30-12-2021 17:35:49.1" and "30-12-2021 17:39:36.8"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table B is of a log file recording data also with timestamps (underlined line is header) around 6000000 datapoints&lt;/P&gt;&lt;P&gt;&lt;U&gt;timestamp, sensor1, sensor2, sensor3&lt;/U&gt;,...&amp;nbsp;&lt;/P&gt;&lt;P&gt;30-12-2021 17:37:21.2, value, value, value,...&lt;/P&gt;&lt;P&gt;30-12-2021 17:37:22.2, value, value, value,...&lt;/P&gt;&lt;P&gt;30-12-2021 17:37:23.2, value, value, value,...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to add a now column to table B with the Period value from Table A&amp;nbsp; based on the value of the timestamp in B.&lt;/P&gt;&lt;P&gt;If timestamp in B is bigger or equal than timestamp in Row (N) in table A AND also smaller than timestamp in Row (N+1) of table A then the period value in Row (N) will be assigned for that record in table B (timestamp in B is between two timestamps in A)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jan 2022 13:35:29 GMT</pubDate>
    <dc:creator>Shahars</dc:creator>
    <dc:date>2022-01-24T13:35:29Z</dc:date>
    <item>
      <title>update table based on timestamp</title>
      <link>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453462#M70038</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have two tables. (A and B)&lt;/P&gt;&lt;P&gt;Table A contain (2000events along the duration of a test) events marking the beginning of a period and the name of the period at specific timestamps&amp;nbsp;(underlined line is header)&lt;/P&gt;&lt;P&gt;&lt;U&gt;TimeStamp, Period&lt;/U&gt;&lt;/P&gt;&lt;P&gt;30-12-2021 17:35:49.1, A&amp;nbsp;&lt;/P&gt;&lt;P&gt;30-12-2021 17:39:36.8, B&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;so Period A is between "30-12-2021 17:35:49.1" and "30-12-2021 17:39:36.8"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table B is of a log file recording data also with timestamps (underlined line is header) around 6000000 datapoints&lt;/P&gt;&lt;P&gt;&lt;U&gt;timestamp, sensor1, sensor2, sensor3&lt;/U&gt;,...&amp;nbsp;&lt;/P&gt;&lt;P&gt;30-12-2021 17:37:21.2, value, value, value,...&lt;/P&gt;&lt;P&gt;30-12-2021 17:37:22.2, value, value, value,...&lt;/P&gt;&lt;P&gt;30-12-2021 17:37:23.2, value, value, value,...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to add a now column to table B with the Period value from Table A&amp;nbsp; based on the value of the timestamp in B.&lt;/P&gt;&lt;P&gt;If timestamp in B is bigger or equal than timestamp in Row (N) in table A AND also smaller than timestamp in Row (N+1) of table A then the period value in Row (N) will be assigned for that record in table B (timestamp in B is between two timestamps in A)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 13:35:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453462#M70038</guid>
      <dc:creator>Shahars</dc:creator>
      <dc:date>2022-01-24T13:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: update table based on timestamp</title>
      <link>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453538#M70039</link>
      <description>&lt;P&gt;Sort the lookup table and use &lt;CODE class=" language-jsl"&gt;Loc Sorted()&lt;/CODE&gt;. Check the function in the Scripting Index to see how it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 14:28:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453538#M70039</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2022-01-24T14:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: update table based on timestamp</title>
      <link>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453568#M70040</link>
      <description>&lt;P&gt;Here is a possible solution using&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26363"&gt;@ErraticAttack&lt;/a&gt;&amp;nbsp;&amp;nbsp;suggestion on the method to use.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dta = Data Table( "table A" );
dtb = Data Table( "table B" );

// Place all timestamp values from Table A &amp;amp; B 
timesa = dta:timestamp &amp;lt;&amp;lt; get values;
timesb = dtb:timestamp &amp;lt;&amp;lt; get values;

// Find the row to add the data to
rows = Loc Sorted( timesa, timesb );

// Add the new columns to Table A
dta &amp;lt;&amp;lt; New Column( "sensor1" );
dta &amp;lt;&amp;lt; New Column( "sensor2" );
dta &amp;lt;&amp;lt; New Column( "sensor3" );

// Loop through matrix rows and add the records to the appropriate
// row in Table A

For( i = 1, i &amp;lt;= N Rows( rows ), i++,
	theRow = rows[i];
	dta:sensor1[theRow] = dtb:sensor1[i];
	dta:sensor2[theRow] = dtb:sensor2[i];
	dta:sensor3[theRow] = dtb:sensor3[i];
);&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 15:37:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453568#M70040</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-01-24T15:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: update table based on timestamp</title>
      <link>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453921#M70067</link>
      <description>&lt;P&gt;Thank you very much ErraticAttach and txnelson&lt;/P&gt;&lt;P&gt;Jim, could it be that&amp;nbsp;the indexing is backwards somehow?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the Loc sorted is getting for each row in B the row number in Table A that contain the information I want to put in table B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, i get an error inside the Loop about the scoping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. if I understand correctly, "rows" should have the same number of rows as table B&lt;/P&gt;&lt;P&gt;2. the parameter "i" increase from 1 to the number of rows in B.&lt;/P&gt;&lt;P&gt;3. in each iteration of the loop , the parameter "theRow" is assigned the corresponding i'th number in "rows".&lt;BR /&gt;so it actually holds the a number representing a specific line in table A that holds the data I want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. so now all we need to do is read the value in the appropriate column in A on that line and put it in the i'th row of B in the column I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I get an error about "scoped data table access requires a data table column or variable in access or evaluation of ..."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;looking at the code I think that the script is referencing the wrong number as the index.&lt;/P&gt;&lt;P&gt;so I Switched between [i] and [theRow]&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="jsl"&gt;For( i = 1, i &amp;lt;= N Rows( rows ), i++,
	theRow = rows[i];
	dta:sensor1[theRow] = dtb:sensor1[i];
	dta:sensor2[theRow] = dtb:sensor2[i];
	dta:sensor3[theRow] = dtb:sensor3[i];
);&amp;nbsp;&amp;nbsp;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;should actually read&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;For( i = 1, i &amp;lt;= N Rows( rows ), i++,
	theRow = rows[i];
	dta:sensor1[i] = dtb:sensor1[theRow];
	dta:sensor2[i] = dtb:sensor2[theRow];
	dta:sensor3[i] = dtb:sensor3[theRow];
);  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;however that does not help either.&lt;/P&gt;&lt;P&gt;I am still not familiar with JSL, so could it be that the way I specify the values or the column and row be incorrect?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, very much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 11:37:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453921#M70067</guid>
      <dc:creator>Shahars</dc:creator>
      <dc:date>2022-01-25T11:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: update table based on timestamp</title>
      <link>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453928#M70068</link>
      <description>&lt;P&gt;solved this by changing the loop to be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( i = 1, i &amp;lt;= N Rows( rows ), i++,
	theRow = rows[i];
	//show(theRow);	
	//show(subscript(dta,theRow,15));
	subscript(dtb,i,8) = subscript(dta,theRow,17);
	subscript(dtb,i,9) = subscript(dta,theRow,15);
	subscript(dtb,i,10) = subscript(dta,theRow,16);
);  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;however if there is a quicker way to run it I would be happy to learn. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 12:08:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/update-table-based-on-timestamp/m-p/453928#M70068</guid>
      <dc:creator>Shahars</dc:creator>
      <dc:date>2022-01-25T12:08:27Z</dc:date>
    </item>
  </channel>
</rss>

